dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.1k stars 1.17k forks source link

Add support for unloading Assembly with WPF control in .NET Core #1764

Open janvorli opened 5 years ago

janvorli commented 5 years ago

The .NET Core 3.0 has a new feature to enable unloading assemblies from memory, called unloadable AssemblyLoadContext. This feature is useful e.g. for implementing unloadable plugins.

In WPF, the MS.Internal.Resources.ResourceManagerWrapper holds on the assemblies containing controls forever (the assemblies are added to an internal container in the AppDomain.CurrentDomain.AssemblyLoad event handler and never removed). So when the assembly is loaded into an unloadable AssemblyLoadContext, the resource container prevents the assembly from ever being unloaded, as the AssemblyLoadContext unloadability relies on GC and all references to the assembly need to go away before it can be unloaded.

To make WPF unloadability friendly, adding an ability to remove an assembly from the resource container would be needed.

It seems the following changes should be sufficient:

weltkante commented 5 years ago

probably related to #1700

wall-code-solutions commented 4 years ago

Is there anything new here? Is this still an issue that will be addressed in the near future?