c# - AppDomain.PrivateBinPath is null -


i'm using appdomain dynamically load/unload dll called logic.dll, in foo subfolder of app. here's code:

public static class wrapper {     private static appdomain domain = null;      public static assembly myresolveeventhandler(object sender, resolveeventargs e)     {         return assembly.loadfrom(e.name);     }      public static void initialize()     {         if (domain != null)         {             appdomain.unload(domain);         }          try         {             string path = environment.currentdirectory + "\\foo\\";              appdomainsetup setup = appdomain.currentdomain.setupinformation;             setup.privatebinpath = "foo";                             domain = appdomain.createdomain("mydomain", null, setup);             domain.assemblyresolve += myresolveeventhandler;              directoryinfo info = new directoryinfo(path);              foreach (fileinfo file in info.getfiles("*.dll"))             {                 string[] filepathstrings = file.fullname.split('\\');                 string filename = filepathstrings[filepathstrings.length - 1];                 if (filename.split('.')[0] == "logic")                 {                     domain.load(filename.replace(".dll", ""));                 }             }         }         catch (exception ex)         {             console.writeline(ex.message);         }                 }         } 

when run code, filenotfound exception: could not load file or assembly 'logic, version=1.0.0.0, culture=neutral, publickeytoken=null' or 1 of dependencies. system cannot find file specified.

using fuslogvw.exe debug, i'm finding appdomain's private path null, though set in code:

=== pre-bind state information === log: displayname = logic, version=1.0.0.0, culture=neutral, publickeytoken=null  (fully-specified) log: appbase = file:///c:/program files/myapp/ log: initial privatepath = null log: dynamic base = null log: cache base = null log: appname = myapp calling assembly : (unknown). === 

is there reason why appdomain private path being nullified?

p.s. can't use app.config change probing value, since causes other problems can't around.

based on @alexei levenkov's comment:

you need careful not "leak" references loaded assembly outside of new appdomain when default appdomain sees type assembly had load assembly default domain first.

if try load dll straight remote appdomain using appdomain.load or assembly.loadfrom, assembly has loaded default appdomain first. since default appdomain wasn't looking anywhere other default privatepath, showing null in log.

to around this, have load assembly using object exists in remote appdomain. answer has example of object loads assembly remote appdomain: https://stackoverflow.com/a/13355702/8464121


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -