|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
AssemblyResolve event not being activated for projectWhen I change the reference to an external library to copylocal=false, The application does not seem to even hit the first line of code before throwing a Assembly not found exception. Making it such that I can't employ the AssemblyResolve event to go find the library at runtime. Long Description: I have a WinForm application in a Project, lets call it ProjectA. I then have a Class Library Project lets call it LibraryB. If I reference LibraryB from ProjectA and set the copylocal attribute to false, then in my ProjectA the AssemblyResolve event should fire and allow me to go find the location of LibraryB and use the Assembly.LoadFrom() method to load LibraryB at runtime. This works for one application I have created as expected, my problem is I have another application with the exact same setup (as far as I can tell), and when the application starts it IMMEDIATELY throws the exception: ________________________________________________________ An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll Additional information: Could not load file or assembly 'LibraryB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. _________________________________________________________ The keyword here is IMMEDIATELY, as in, it never hits a breakpoint, I have even tried to debug it using the "Step Into" function from the beginning and it appears to not hit a single line of code before throwing the exception. Any ideas on where to look to solve this problem? Thank You Joel OK, I guess I will reply to my own post as to what the solution was, maybe
someone else will have this problem and this might help. In the first post, there was actually not enough information to solve the problem, here is the subtlety between the application where the AssemblyResolve would fire and the application where it would not. In the application that worked as expected, the application ONLY called classes from the referenced library by instantiating an object in code, such as LibraryB.Class1 myClass = new Class1(); as soon as the application hit the first reference to LibraryB, it realized it could not find the assembly and the ApplicationResolve event successfully fired. This allowed me to go find the correct assembly (in a different folder from the applications executable) and everything was happy happy. In the application that did not fire the ApplicationResolve event it turns out I was INHERITING from a class in the referenced library. Like this: public class ProjectA.MyCoolClass : LibraryB.Class1 For some reason I still don't understand, the application must know where the referenced library for an inherited class is, before a single line of code is executed. This makes it such that if I hook into the AssemblyResolve event as the FIRST line of code, it still won't be executed, so I can never load the referenced library by searching for it myself. It's an interesting subtlety and hopefully it will help anyone who has the same problem. If anyone can point me to information on specifically why this works this way, or solutions they have used to get around it (I already understand I can put it in my config, or use the GAC, I am trying to avoid both of those solutions) I would appreciate if they would post it here. Here are some keywords I searched on that may lead others with this problem to this post: Visual Studio AppDomain Assembly.LoadFrom AssemblyName GetExecutingAssembly MyResolveEventHandler -Joel Show quote "JoelErik" wrote: > Short Description: > When I change the reference to an external library to copylocal=false, The > application does not seem to even hit the first line of code before throwing > a Assembly not found exception. Making it such that I can't employ the > AssemblyResolve event to go find the library at runtime. > > > Long Description: > I have a WinForm application in a Project, lets call it ProjectA. > > I then have a Class Library Project lets call it LibraryB. > > If I reference LibraryB from ProjectA and set the copylocal attribute to > false, then in my ProjectA the AssemblyResolve event should fire and allow me > to go find the location of LibraryB and use the Assembly.LoadFrom() method to > load LibraryB at runtime. > > This works for one application I have created as expected, my problem is I > have another application with the exact same setup (as far as I can tell), > and when the application starts it IMMEDIATELY throws the exception: > > ________________________________________________________ > An unhandled exception of type 'System.IO.FileNotFoundException' occurred in > mscorlib.dll > > Additional information: Could not load file or assembly 'LibraryB, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its > dependencies. The system cannot find the file specified. > _________________________________________________________ > > The keyword here is IMMEDIATELY, as in, it never hits a breakpoint, I have > even tried to debug it using the "Step Into" function from the beginning and > it appears to not hit a single line of code before throwing the exception. > > Any ideas on where to look to solve this problem? > > Thank You > > Joel > > |
|||||||||||||||||||||||