AppDomain.CreateInstanceAndUnwrap of shared (GAC) assemblies

S

Sebastien Girard

Hi everyone,

I am trying to load a shared assembly in it's own application domain. I
created a simple Windows Application with 1 button that executes the code
below. It is trying to load a very simple assembly 'ClassLibrary1' that is
located in the GAC.
The call to CreateInstanceAndUnwrap is unable to locate the assembly. I
have no clue as to why the application domain can't load a shared assembly,
any help is welcome.

// Prepare Setup
AppDomainSetup appDomainSetup = new AppDomainSetup();
appDomainSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
appDomainSetup.ApplicationName = "MyAppDomainName";

// Create Application domain
AppDomain myAppDomain = AppDomain.CreateDomain("MyAppDomainName", null,
appDomainSetup);
try
{
// Load shared assembly
myAppDomain.CreateInstanceAndUnwrap("ClassLibrary1",
"ClassLibrary1.Class1");
}
catch(Exception ex)
{
// Crashes with message "File or assembly name ClassLibrary1, or one of
it's dependencices was not found."
MessageBox.Show(ex.Message);
}
 
R

Richard Blewett [DevelopMentor]

You;ll have to fully qualify the assembly name otherwise the assembly resolver will simply probe under teh APPBASE. So you want:

"ClassLibrary1, Version=*.*.*.*, Culture=neutral, PublicKeyToken=******************" where the asterisks are replaced by the real values for your assembly (I assumed the assembly was cluture neutral)

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.framework/<[email protected]>

Hi everyone,

I am trying to load a shared assembly in it's own application domain. I
created a simple Windows Application with 1 button that executes the code
below. It is trying to load a very simple assembly 'ClassLibrary1' that is
located in the GAC.
The call to CreateInstanceAndUnwrap is unable to locate the assembly. I
have no clue as to why the application domain can't load a shared assembly,
any help is welcome.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top