.NETGURU
Assembly.Load() with alternate subdirectory for other assemblies which have dependencies
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.clr.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Jim
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...
Reply to this message...
 
    
David Levine
Before you load any assembly with a dependency on the common.dll or loading
it directly, call
AppDomain.CurrentDomain.AppendPrivatePath("ExternalLibrary");

This tells the runtime where it can look below the application base
directory for other assemblies, and avoids needing to explicity load the
assembly using LoadFrom.

"Jim" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Christian Heide Damm (VIP)
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

---

"Jim" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.AppDomain
System.Reflection.Assembly
System.Reflection.AssemblyName




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification