Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin assembly loading #2

Open
ivanbiljan opened this issue Sep 23, 2020 · 2 comments
Open

Fix plugin assembly loading #2

ivanbiljan opened this issue Sep 23, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@ivanbiljan
Copy link

foreach (var path in Directory.EnumerateFiles("plugins", "*.dll"))
{
try
{
var assembly = Assembly.LoadFile(path);
server.Load(assembly);
}

The above snippet is bound to throw an exception. Assume the following structure:

logs/
plugins/
orion-launcher.exe

When called with a relative path (such as the above snippet), Directory.EnumerateFiles will return a collection of file names with their relative paths. Since Assembly.LoadFile requires an absolute path to load the assembly we're left with an unhandled argument exception.

There are 2 ways we could go about fixing this:

  • Keep Assembly.LoadFile and pass in an absolute path obtained via a Path.GetFullPath call
  • Replace Assembly.LoadFile with Assembly.LoadFrom which accepts a relative URI as well as an absolute one. This yields additional benefits such as hinting the runtime where to load dependencies from

Both solutions are one-liners.

@kevzhao2
Copy link
Member

Either of those would work fine. Perhaps we should batch in unloadable assembly contexts as well with this change?

@kevzhao2 kevzhao2 added the bug Something isn't working label Sep 23, 2020
@ivanbiljan
Copy link
Author

Sounds good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants