.net assembly - C#: Resolving multiple assemblies using the AssemblyResolve function -
i'm attempting make single exe app. end, have 2 dlls tagged embedded resouces in app. can use appdomain.currentdomain.assemblyresolve += new resolveeventhandler(myresolve)
method return assembly when event fires.
the difficulty i'm running methods within application reference multiple assemblies. when use above event handler load , return assembly, application looks method in wrong assembly file, , "type load exception".
therefore, how can load assemblies application looks in proper places methods might use?
kind regards.
code sample:
dll resolution:
appdomain.currentdomain.assemblyresolve += new resolveeventhandler(resolvedll) static assembly resolvedll(object sender, resolveeventargs args) { using (var stream = assembly.getexecutingassembly().getmanifestresourcestream("myapplication.resources.mydll1.dll")) { byte[] assemblydata = new byte[stream.length]; stream.read(assemblydata, 0, assemblydata.length); return assembly.load(assemblydata); //obviously resolves first dll, how can resolve second? } } void somemethod() { mydll1.class.callamethod() mydll2.class.callanothermethod() //type load exception - assembly resolution told in mydll1. }
as per suggestion of l.b., tried simple if/then block using args.name
. has done trick.
if (args.name == "mydll1, version=1.0.0.0, culture=neutral, publickeytoken=null") { using (var stream = assembly.getexecutingassembly().getmanifestresourcestream("myapplication.resources.mydll1.dll")) { byte[] assemblydata = new byte[stream.length]; stream.read(assemblydata, 0, assemblydata.length); return assembly.load(assemblydata); } } else if (args.name == "mydll2, version=1.0.0.0, culture=neutral, publickeytoken=null") { using (var stream = assembly.getexecutingassembly().getmanifestresourcestream("myapplication.resources.mydll2.dll")) { byte[] assemblydata = new byte[stream.length]; stream.read(assemblydata, 0, assemblydata.length); return assembly.load(assemblydata); } }
Comments
Post a Comment