> 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