How do i dynamicaly load and unload a C# dll at runtime

J

John M Deal

Actually you can do this. You will need to look into crating new
application domains (via System.AppDomain.CreateDomain), using
reflection to load the dll that you are interested in (see the
System.Reflection namespace), then unloading the AppDomain when you are
done with the dll (using System.AppDomain.Unload).

If you are interested in seeing an "in production" working example of an
application that can do this, take a look at NUnit. NUnit allows you to
replace the test DLLs at runtime and the application will unload the
ones it was using then load up the new ones.

Hope this gets you going in the right direction.

Have A Better One!

John M Deal, MCP
Necessity Software
 
G

Guest

I'm not sure if this is what you need.
You have a dll and you want to late bind...

take a look at the following code, it loads a form from a dll. Everything
can be configured at runtime...


string assembly = "ClassLibrary1.dll";
string method = "Show";
string type = "Form1";
Assembly assemblyInstance = Assembly.LoadFrom(assembly);
assemblyInstance.GetType(type).InvokeMember(method, BindingFlags.Public |
BindingFlags.InvokeMethod |
BindingFlags.Instance,null,assemblyInstance.CreateInstance(type), null);
 

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