loading dll dynamically

  • Thread starter Thread starter CSharper
  • Start date Start date
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 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
 
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
 
Back
Top