c# - Assembly loaded from Resources raises Could not load file or assembly -


i writing simple application should create shortcuts. use interop.iwshruntimelibrary add embedded resource.

on class init call

assembly.load(resources.interop_iwshruntimelibrary); 

i tried:

appdomain.currentdomain.load(resources.interop_iwshruntimelibrary); 

when build application in visualstudio output window see assembly loaded:

loaded "interop.iwshruntimelibrary".

but, when try use objects in assembly gives me exception:

"could not load file or assembly "interop.iwshruntimelibrary, version=1.0.0.0, culture=neutral, publickeytoken=null".

it not simple think , if visualstudio says reference loaded means references of project loaded during build. has nothing tring achieve.

the easiest way bind appdomain.assemblyresolve event called when resolution of assembly fails:

appdomain currentdomain = appdomain.currentdomain; currentdomain.assemblyresolve += new resolveeventhandler(myresolveeventhandler); 

then:

private assembly myresolveeventhandler(object sender,resolveeventargs args) {     assembly rtn=null;      //check assembly names have raised "assemblyresolve" event.     if(args.name=="your resource assembly name")     {         //load resource         stream resxstream = assembly.getexecutingassembly().getmanifestresourcestream("your resource assembly name");         byte[] buffer = new byte[resxstream.length];         resxstream.read(buffer, 0, resxstream.length);         rtn = assembly.load(buffer);     }     return rtn;          } 

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 -