简体   繁体   中英

Load and Unload assembly AppDomain.Load(bytes)

I want to do something like this:

byte[] bytes = item.CompiledRule;
AppDomain domain = AppDomain.CreateDomain("TestDomain");
Assembly a = domain.Load(bytes);
//Something do with Assembly 
AppDomain.Unload(domain);

I have only assembly bytes. When I dont use AppDomain It works perfect, but when i do it like this it crushed:

System.IO.FileNotFoundException: Could not load file or assembly

When you load assembly from a byte array, it's dependencies are not resolved automatically. One possible way to solve the problem is to subscribe to AppDomain.AssemblyResolve event to load your dependencies. Note that the resolution code must run inside that 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