Thanx Frans, In my situation my dll is loaded due to an unmanaged call into a managed exported function. So I dont have control over the AppDomain, because the loader isn't finished loading my assembly. If an assembly is loaded due to a call into an exported function, the BaseDirectory is from the hosting application, and even assemblies that are present in the same directory as the main assembly are not found.
So, I have to use 2 different assemblies, or prevent the loader from complaining about an unresolved assembly. Peter ----- Original Message ----- From: "Frans Bouma" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Tuesday, April 04, 2006 10:03 AM Subject: Re: [ADVANCED-DOTNET] weak references to assemblies |> Before I can use code form an assembly I have to reference it | > from your code. | > Now, if the loader loads the main assembly, it does a search | > for the referenced assemblies too, possibly ending with a | > failure because one or more assemblies could not be found. | > | > Is it possible to do a "weak reference" (not a weak reference | > in GC-terms!!) to the needed assemblies, so that the loader | > does not complain if those assemblies where not found? | > From your code you could easily check if the needed assembly | > was loaded, and if not, take a different codepath preventing | > use of the not loaded assembly. | | You can intercept a load failure of an assembly and act upon it. You do that with an eventhandler bound to the | AssemblyResolve event of the current appdomain: | AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler( OnProjectLoadAssemblyResolveFailure ); | | Here I bound an event handler which resolves assembly load failures during a binary deserialization process which can have be | terminated due to assembly load failures. | | In the event handler, you load the assembly manually, by using Assembly.LoadFile for example or other load methods. | | If you simply want to avoid loading assembly Foo which failed to load, you don't have to do anything except be prepared for | an exception when you try to load Foo, as a failed load means no load at all :) | | Frans | | =================================== | This list is hosted by DevelopMentorĀ® http://www.develop.com | | View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
