We know that a .NET assembly is loaded at the last possible moment - when you enter a method that references a something in the foreign assembly.
When is an assembly unloaded? Is it when there are no longer any references to any classes/resources in the assembly? Is it never?
Imagine the class in the foreign assembly has a private static. The static is initialized when first needed. Presumably that static will no longer contain a value when the static variable is removed from memory.
When is an unreferenced static class removed from memory?
When is a .NET assembly unloaded?
It's only unloaded when the AppDomain
that it's loaded into is unloaded, e.g. as part of a web app recycling.
Any classes within the assembly stay loaded while the assembly is loaded, so therefore they stick around until the AppDomain
is unloaded too.
See more on this question at Stackoverflow