简体   繁体   中英

.Net can't resolve assemblies referenced by a Prism module

I have a Prism modular application, where modules are built in a directory catalogue. If my module references an assembly, .Net assembly binder fails to locate that assembly at run time, because it is probing inside host applications bin folder, ignoring the modules bin folder altogether. The only way to make it work is to reference the assembly in host app as well. This is unacceptable IMO, because the whole point of a modular application is that the host app is decoupled from modules, hence it shouldn't be aware of what dlls they reference.

Is there a way to configure assembly loader/binder to look in the module's output folder for the referenced assemblies?

I found this question, which doesn't give any solutions other than adding references in the host app.

Prism assembly reference failure: System.Windows.Interactivity

I don't know if there is something out of the box in Prism, but you could manually implement something using AppDomain.AssemblyResolve event.

Diagnose using AssemblyLog

Have you tried enabling assembly binding logging (FusionLog) to confirm it is definitely not looking in that folder already?

See How to enable assembly bind failure logging (Fusion) in .NET how to enable it.

And Scott Hanselmans Blog for a tutorial on how to use it (in case you haven't used it before): Using Fusion Log Viewer to Debug Obscure Loader Errors

AppDomain.AssemblyResolve Event

Have a look at MSDN: AppDomain.AssemblyResolve event, which an an example of dynamically loading a specific module can be found here: MS Docs: Resolving Assembly Loads

Note that you can get the requesting Assembly Name using ResolveEventArgs.RequestingAssembly which you could potentially use to figure out the folder to look for the assembly in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM