Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
When I try to load the assembly into a separate Application domain, I get an exception.

Here is my code:
C#
domain = AppDomain.CreateDomain("MyDomain");
mi = default(MethodInfo);

Assembly a = domain.Load(path); //Exception thrown here

Type type = a.GetType(nameSpace.ClassName);

mi = type.GetMethod("Greeting");
Console.WriteLine(mi.Invoke(null, new object[] { "Ryan" }).ToString())

I get the following exception when trying domain.load:
Could not load file or assembly 'C:\\temp\\good.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

I have verified that the file exists within the location, and it is there.

Does anybody know what this problem might be?
Posted
Updated 2-May-12 22:34pm
v3

byte[] data = System.IO.File.ReadAllBytes(filename);
Assembly assembly = Assembly.Load(data);
works to.
 
Share this answer
 
Look here:
MSDN: AppDomain.Load Method[^]

It does not take assembly path as a parameter. The way you define, it is trying to find an assembly that has name 'C:\temp\good.dll'. This is wrong.

Try:
C#
string fileToLoad = @"C:\temp\good.dll";
AssemblyName assamblyName = AssemblyName.GetAssemblyName(fileToLoad);
AppDomain myDomain = AppDomain.CreateDomain("MyDomain");                   
Assembly myAssambly = myDomain.Load(assamblyName);
 
Share this answer
 
Comments
Andrew797 3-May-12 4:56am    
Thank you. This works perfectly.
Sandeep Mewara 3-May-12 5:11am    
Good to know. :thumbsup:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900