loading dll dynamically

C

CSharper

I have a user request which I get will tell me which dll to load and
which method to execute. What is the best of doing it? One thing I
need to be careful is not to keep the dll always in the app domain
since the dll could change in the backend and user might have dropped
a new one. So always I need to load the dll as well. So I have the
following questions
1. I can use reflection to load dll but how can call a particular
method in assembly that is passed in as a parameter?
2. How can I load and unload dll on the fly?
Thanks,
 
I

Ignacio Machin ( .NET/ C# MVP )

I have a user request which I get will tell me which dll to load and
which method to execute. What is the best of doing it? One thing I
need to be careful is not to keep the dll always in the app domain
since the dll could change in the backend and user might have dropped
a new one. So always I need to load the dll as well. So I have the
following questions
1. I can use reflection to load dll but how can call a particular
method in assembly that is passed in as a parameter?
2. How can I load and unload dll on the fly?
Thanks,

Assembly.Load will load the assembly.
Activator.CreateInstance will create the instance giving its full
name.

There are other ways to create an instance though, but those two will
work
 
A

Arne Vajhøj

CSharper said:
I have a user request which I get will tell me which dll to load and
which method to execute. What is the best of doing it? One thing I
need to be careful is not to keep the dll always in the app domain
since the dll could change in the backend and user might have dropped
a new one. So always I need to load the dll as well. So I have the
following questions
1. I can use reflection to load dll but how can call a particular
method in assembly that is passed in as a parameter?
2. How can I load and unload dll on the fly?

Outline:


AppDomain d = AppDomain.CreateDomain("somename");
ISomeInterface somevar =
(ISomeInterface)d.CreateInstanceAndUnwrap(somefilenamevar, "SomeClass");
somevar.SomeMethod();
AppDomain.Unload(d);

Arne
 

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

Similar Threads

DLL loading Question 5
C# DLL unloading appdomain 2
loading dll at runtime 5
application domain 6
how to dynamically load dll ? 1
Load User Control Dynamically 3
reflection question 5
How to load an assembly? 4

Top