Featured post
C#: How to embed DLL into resourcefile (no dll copy in program directory) -
i have c# application (project a) requires x.dll. have added project produces x.dll reference in visual studio. have added release build of x.dll resource file in binary. have told project not copy x.dll output directory.
now want a.exe load, "hey can't find file", in resource file , use assembly.load(byte[]) x.dll back. have code re-magicifies dll back, code never called.
currently have bone simple project, trying work. compile ok. when run it, filenotfoundexception on x.dll.
i have:
[stathread] static void main() { appdomain.currentdomain.assemblyresolve += new resolveeventhandler(currentdomain_assemblyresolve); }
but breakpoint in *currentdomain_assemblyresolve* never gets hit. filenotfoundexception immediately. surely there missing?
this question seems similar trying achieve, , worked asker.
are doing differently? specifically, if you're targetting older version of .net framework, maybe that's hint understanding why application behaving differently.
another direction, use tool such fusion log viewer analyze going on when tried load assembly. may give more hints. if manage log information, posting in question may figure out.
edit: explanation, following comment.
well, think know problem is.
in main
method, refering type in other dll. doing in static code, i.e. use type explicitly in code (as opposed loading dynamically name).
why problem? clr tries load assembly in order jit main
itself.
your filenotfoundexception
thrown while main
being compiled. main
didn't start running, , therefore event handler wasn't registered.
a simple way check if i'm right change code this:
static public void main(string[] args) { appdomain.currentdomain.assemblyresolve += myeventhandler; mymain(); } // clr try load assembly before starting execution // of method. needs assembly in order jit method because has // know thing type. static public void mymain() { using(var thing = new thing()) { // ... } }
the important difference main
has no dependency on assembly, there no problem jit , run it.
by time mymain
being jit'ed, event handler in place can manually load assembly.
by way, avoid possible similar pitfall, make sure class in main
defined doesn't have field type other assembly, because in case also, clr try loading assembly before main
starts, in order compile it.
- Get link
- X
- Other Apps
Comments
Post a Comment