One solution would be to load OurCompany.Common.dll v1.2.0.0 _before_ you
load ExternalLibrary.dll - that way it doesn't have to look for it when it
needs it.
Another way would be to subscribe to the AppDomain.AssemblyResolve event.
When that event is raised for the "OurCompany.Common.dll, version 1.2.0.0,
...." assembly, you load it from c:\ExternalLibrary. This is the lazy variant
of the first solution.
Reg. the question about load contexts...
First of all, I don't understand how you can load ExternalLibrary.dll by
Assembly.Load("ExternalLibrary"). I would think you'd need to say
AssemblyName externalLibraryName = new AssemblyName("ExternalLibrary");
// include version etc. if you want
externalLibraryName.Location = @"c:\temp\ExternalLibrary";
Assembly.Load(externalLibraryName);
Anyway, it looks like it's loaded in the LoadFrom context - in which case I
would actually expect it to find ExternalLibrary.dll v1.2.0.0 because it is
in the same directory. If it is in fact loaded in the Load context, I would
NOT expect it to find ExternalLibrary.dll v1.2.0.0.
Christian
---
[quoted text, click to view] "Jim" <jcwiese@yahoo.com> wrote in message
news:1b998b5f.0408310900.64ee9d82@posting.google.com...
>I have a question about dependent assemblies of asseblies that are
> loaded with Assembly.Load(). I have a directory structure with the
> following format:
>
> C:\temp\
> -> myApp.exe
> -> OurCompany.Common.dll (version 1.5.0.0 with common routines,
> strongly signed)
>
> C:\temp\ExternalLibrary
> -> ExternalLibrary.dll
> -> OurCompany.Common.dll (version 1.2.0.0 with common routines,
> strongly signed)
>
>
> From "myApp.exe", the following code is used:
>
> Assembly loaded = Assembly.Load( "ExternalLibrary" ) ;
> object classToUse =
> loaded.CreateInstance("ClassInsideExternalLibrary") ;
>
> ... the loading of the assembly seems to work just fine, but when
> CreateInstance() is called, it fails because it can not find
> OurCompany.Common.dll with version 1.2, which is a dependency in
> ExternalLibrary.dll's manifest. From my understanding, it should have
> been loaded since it resides inside the Load() context. Is this
> correct? If not, any suggestions of how to make this work without the
> GAC would be appreciated. I can temporarily resolve this issue by
> using a <bindingRedirect> in the myApp.exe.config file. This is much
> less usefull as it makes a central location with all of the detailed
> knowledge of each of the loaded assemblies.
>
> Thanks in advance...