views:

60

answers:

1

The Code as below which i'm trying to load a dll dynamically is not working.

AppDomain appDomain = AppDomain.CreateDomain("DllDomain");

Assembly a = appDomain.Load(fileName);

//Assembly a = Assembly.LoadFrom(fileName);

objType = a.GetType(className);

obj = a.CreateInstance(className);

object[] args = new object[1];

args[0]=(object) "test";

object ret = objType.InvokeMember("Perform", BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, args);

string output = ret.ToString();

obj = null;

AppDomain.Unload(appDomain);

this is the code i am using inside a WCF service but still it does not work.

Heard that we can acheive using 'Shadow Copying' in AppDomain. But i dont know anything about 'Shadow Copying' and how to implement the same in the above code.

Please provide working code as example for 'Shadow Copying'.

-B.S.

A: 

You can load assemblies into an application domain but you cannot unload them from that domain.

However, in one application domain you can create a second application domain and load an assembly into the second application domain. Later you can then choose to unload the second application domain which in turn unloads the assembly that you loaded into the second application domain.

This is the basic principle. In practice you will find a number of obstacles (they changed through the versions of .NET) to be resolved in particular when you set up some form of communication between the application domains.

Providing working code here would probably be too big in size.

John