简体   繁体   中英

Assembly.CreateInstance with different assembly references

I've created a plugin architecture that supports reloading of the plugins and doesn't use multiple AppDomains. I simply create a new assembly, when the dll changes, with the Assembly.Load(Byte[]) method and then create the plugin instance via myAssembly.CreateInstance(type.FullName) . It all works fine and well. Now I wanted to support that the plugin can have referenced assembies and those references can be changed on the fly. I've implemented Appdomain.AssemblyResolve event and it works, of course, to load the references of the plugin once but not to reload the referenced dlls when they change.

Is there any way of creating an instance from an assembly and telling it which other assemblies to use as a reference?

Small note: I know about app domains but cannot use them because I don't want to serialize the data I have in memory (many GBs).

.NET will find your references according to the qualified assembly name and AssemblyResolve will only fire if .NET cannot already resolve the assembly it is looking for automatically (by matching the qualified name and load context to a loaded assembly, or loading from the probing path).

So if you have already resolved a particular referenced type, or it is resolved automatically, you won't get an opportunity to load it from somewhere else. Also, because assemblies (identified by the full assembly name) loaded in a specific context in a given AppDomain cannot be unloaded, you are not going to be able to unload/reload those referenced assemblies in the same AppDomain.

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