c# - Load assemblies from file to custom AppDomain without knowing type -


i need load several .dll files in separate appdomain, operations them , unload appdomain. can through createinstansefrom need know name of type.

if types in given assembly, can filter out mine.

i can types through reflection, works current appdomain, right? it's no use loading files first in current domain, types , load them custom domain.

is there method load assembly file custom app domain?

instead of trying use class 1 of target assemblies in createinstancefrom/createinstancefromandunwrap call, use class of own. can create well-known class inside appdomain , call well-known method. inside well-known method, process assemblies.

// class created inside temporary appdomain. class myclass : marshalbyrefobject {     // call executed inside temporary appdomain.     void processassemblies(string[] assemblypaths)     {         // assemblies processed here         foreach (var assemblypath in assemblypaths)         {             var asm = assembly.loadfrom(assemblypath);             ...         }     } } 

and use process assemblies:

string[] assembliestoprocess = ...;  // create temporary appdomain var appdomain = appdomain.createdomain(...); try {     // create myclass instance within temporary appdomain     var o = (myclass) appdomain.createinstancefromandunwrap(         typeof(myclass).assembly.location,         typeof(myclass).fullname);      // call temporary appdomain process assemblies     o.processassemblies(assembliestoprocess); } {     // unload temporary appdomain     appdomain.unload(appdomain); } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -