jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
10.91k stars 1.16k forks source link

Assembly.LoadFile("c:\SomePath\MyApp.dll") doesn't find handlers #961

Closed TiisangMguni closed 9 months ago

TiisangMguni commented 9 months ago

Does anyone have a idea why this works:

assemblies.Add(typeof(SampleUseCaseHandler).Assembly);
builder.AddMediatR(assemblies)

But this doesn't work:

assemblies.Add(Assembly.LoadFile("c:\SomePath\MyApp.dll"));`
builder.AddMediatR(assemblies)

The reason why we need to load the DLL from disk is because we want to load "plugins" during runtime and cannot have a direct reference to the plugin DLLs

jbogard commented 9 months ago

This is better for StackOverflow, as it has less to do with MediatR and more to do with dynamically loading assemblies.

christoneethling commented 9 months ago

I had the same issue with MediatR and solved it by using LoadFrom(path), instead of LoadFile(path)

Like this:

assemblies.Add(Assembly.LoadFrom("c:\SomePath\MyApp.dll"));`
builder.AddMediatR(assemblies)