DLL unloading automatically

Y

Yash Ganthe

Hi,

In my program, I load a DLL using Assembly.LoadFrom(). The program has
no Reference added to the DLL. It is loaded dynamically. The DLL has a
class with a static constructor. I can see that it executes when the
assembly is loaded. However, after a few hours, the static constructor
executes again. There is only one place in the program from which the
Assembly is loaded and this does not happen in a loop.
This makes me think that the assembly has got Unloaded somehow and has
automatically been reloaded. In what circumstances is this possible?
Is there any other explanation to the static constructor being
executed twice?

This is on .NET 3.0, C#

Thanks,
Yash
 
F

Family Tree Mike

Yash said:
Hi,

In my program, I load a DLL using Assembly.LoadFrom(). The program has
no Reference added to the DLL. It is loaded dynamically. The DLL has a
class with a static constructor. I can see that it executes when the
assembly is loaded. However, after a few hours, the static constructor
executes again. There is only one place in the program from which the
Assembly is loaded and this does not happen in a loop.
This makes me think that the assembly has got Unloaded somehow and has
automatically been reloaded. In what circumstances is this possible?
Is there any other explanation to the static constructor being
executed twice?

This is on .NET 3.0, C#

Thanks,
Yash

Try displaying the stack trace in the static constructor to see why it
might be called.
 
C

Chris Dunaway

Hi,

In my program, I load a DLL using Assembly.LoadFrom(). The program has
no Reference added to the DLL. It is loaded dynamically. The DLL has a
class with a static constructor. I can see that it executes when the
assembly is loaded. However, after a few hours, the static constructor
executes again. There is only one place in the program from which the
Assembly is loaded and this does not happen in a loop.
This makes me think that the assembly has got Unloaded somehow and has
automatically been reloaded. In what circumstances is this possible?
Is there any other explanation to the static constructor being
executed twice?

This is on .NET 3.0, C#

Thanks,
Yash

Unless you loaded the assembly in a separate AppDomain, I don't think
it will be unloaded until the App closes.

I'm not sure how instances of static classes are handled by the
garbage collector, but perhaps your class is being collected somehow,
so that the next time you access the static members, the static
constructor is being executed again.
 

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