1

I have a class which has public Assembly LoadedAssembly { set; get; }

var assemblyName = AssemblyName.GetAssemblyName(fullPathToDLLFile);
myClass.LoadedAssembly = Assembly.Load(assemblyName);

This class I keep under Application.Current.Properties["MyClass"].

I try to null it like Application.Current.Properties["MyClass"] = null; but it doesn't help.

I see that the loaded assembly works (It has a timer inside and it is working).

How do I can clean it?

(I don't use something like AppDomain d = AppDomain.CreateDomain("NewDomain", null, domaininfo); to load assembly.)

NoWar
  • 36,338
  • 80
  • 323
  • 498

2 Answers2

3

You can't arbitrarily unload an assembly, you must instead unload the AppDomain in which the assembly is loaded (which unloads all assemblies in the AppDomain). If you're not loading it into a separate AppDomain, then the only way to do that would be to shut down the application.

There are various links in this question with details on why this is not supported: How to unload an assembly from the primary AppDomain?

Community
  • 1
  • 1
Iridium
  • 23,323
  • 6
  • 52
  • 74
2

You cannot unload an assembly, but you can unload the AppDomain that you loaded the assembly into. See this explanation.

Ventsyslav Raikov
  • 6,882
  • 1
  • 25
  • 28