Skip to content

Fix plugin assembly loading #2

@ivanbiljan

Description

@ivanbiljan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions