c# - AppDomain Execute Assembly -


i trying load assembly (dll) appdomain , call entry point. (essentially bootstrap package azure environment) have been following article (how create application domain , run application in it?) , think doing right, i'm having issues.

i have used several articles on here me far am, keep running filenotfoundexception described in unable load executing assembly new appdomain, filenotfoundexception. problem solution doesn't work. assembly trying execute exists in different location. applicationbase needs folder of assembly trying execute.

var othertype = typeof(bootstrapproxy); var domaininfo = new appdomainsetup     {         configurationfile = executingassembly + ".config",         applicationbase = _root     }; evidence adevidence = appdomain.currentdomain.evidence; _domain = appdomain.createdomain(_type.tostring(), adevidence, domaininfo); _domain.assemblyresolve += (sender, args) =>     {         var lookuppath = path.getdirectoryname(assembly.getexecutingassembly().location);         if (lookuppath == null) return null;         var assemblyname = new assemblyname(args.name).name;         var assemblyfilename = path.combine(lookuppath, assemblyname + ".dll");         var assembly = assembly.loadfrom(assemblyfilename);         return assembly;     }; var proxy = _domain.createinstanceandunwrap(othertype.assembly.fullname, othertype.fullname) bootstrapproxy; 

the last line throws exception , assemblyresolve event never fires off (as determined placing breakpoint on var lookuppath line.

i have tried appdomain.currentdomain.assemblyresolve event same handler above no luck. have tried creating same handler inside bootstrapproxy class.

i think doing make note of first paragraph, if i'm off base, i'm not averse doing things different way.

update:

i have changed code around forcibly load assemblies new appdomain , still have issues.

var othertype = typeof(bootstrapproxy); var domaininfo = new appdomainsetup     {         configurationfile = executingassembly + ".config",         applicationbase = _root     }; evidence adevidence = appdomain.currentdomain.evidence; _domain = appdomain.createdomain(_type.tostring(), adevidence, domaininfo); var deps = assembly.getexecutingassembly().getreferencedassemblies(); foreach (var dep in deps) {     var lookuppath = path.getdirectoryname(assembly.getexecutingassembly().location);     if (lookuppath == null) continue;     var assemblyname = new assemblyname(dep.name).name;     var assemblyfilename = path.combine(lookuppath, assemblyname + ".dll");     if (file.exists(assemblyfilename))         _domain.load(file.readallbytes(assemblyfilename)); } _domain.load(file.readallbytes(assembly.getexecutingassembly().location)); var sl = _domain.getassemblies().toarray(); var proxy = _domain.createinstanceandunwrap(othertype.assembly.fullname, othertype.fullname) bootstrapproxy; 

sl shows dlls, including 1 referenced in filenotfoundexception loaded in new appdomain.

public class bootstrapproxy : marshalbyrefobject {     public void main()     {         console.writeline("magic happened.");     } } 

update 2:

i changed around this:

var deps = assembly.getexecutingassembly().getreferencedassemblies(); foreach (var dep in deps) {     var lookuppath = path.getdirectoryname(assembly.getexecutingassembly().location);     if (lookuppath == null) continue;     var assemblyname = new assemblyname(dep.name).name;     var assemblyfilename = path.combine(lookuppath, assemblyname + ".dll");     if (file.exists(assemblyfilename))         file.copy(assemblyfilename, path.combine(_root, assemblyname + ".dll")); }  file.copy(assembly.getexecutingassembly().location, path.combine(_root, path.getfilename(assembly.getexecutingassembly().location))); var othertype = typeof(bootstrapproxy); var domaininfo = new appdomainsetup     {         configurationfile = executingassembly + ".config",         applicationbase = _root     }; evidence adevidence = appdomain.currentdomain.evidence; _domain = appdomain.createdomain(_type.tostring(), adevidence, domaininfo); var proxy = _domain.createinstanceandunwrap(othertype.assembly.fullname, othertype.fullname) bootstrapproxy; if (proxy != null) {     proxy.main(); } 

this method of copying assembly , references applicationbase of new appdomain not ideal, there few common references , end version conflicts , other issues.

just guess, problem here:

var othertype = typeof(bootstrapproxy); 

by doing this, loading assembly calling appdomain. due initialization, attempts load assembly not present in calling domain's lookup path. kaboom!

to solve this:

refer othertype qualified name , passing in assembly name string too. (i think might away using fqn of type)

also. should not handle assemblyresolve assemblies outside appdomain.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -