AppDomain.Load

Hi!

I have some problems with loading assemblies in a new AppDomain. When I invoke myAppDomain.Load(string) I get the following exception:

File or assembly name ...dll, or one of its dependencies, was not found.

I have tried loading an assembly that does not depend on any assemblies other than those referenced by console applications. I have googled a lot, but have not found any magic line of code that fixes this.

This is roughly what I do:


Evidence currentEvidence = AppDomain.CurrentDomain.Evidence;
Evidence newEvidence =new Evidence(currentEvidence);;

AppDomainSetup domainSetup =new AppDomainSetup();
AppDomain newDomain =null;
Assembly assembly =null;

domainSetup.ApplicationBase = Path.GetDirectoryName(myAssembly);
newDomain = AppDomain.CreateDomain("My Domain", newEvidence, domainSetup);

assembly = newDomain.Load(Path.GetFullPath(myAssembly));

What am I doing wrong?

Thanks in advance,
Nille

[1392 byte] By [Nille] at [2007-12-17]
# 1

Hi,

AppDomain.Load has the side effect that it implicitly marshals the freshly loaded assembly back into your calling app domain which yields an load attempt there. Given your setup, this is likely to fail because of different private pathes. The fusion log should confirm this.

As a general note, never try to load assemblies directly but always access types from them. The system will then load the required assemblies.

Thanks, Thorsten.

tbrunk at 2007-9-8 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified