Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
janvorli opened this issue Sep 3, 2019 · 3 comments
Open

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

janvorli opened this issue Sep 3, 2019 · 3 comments
Labels
Enhancement Requested Product code improvement that does NOT require public API changes/additions rank20 Rank: Priority/rank on a scale of (1..100)
Milestone

Comments

@janvorli
Copy link
Member

janvorli commented Sep 3, 2019

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:

  • In the existing AppDomain.CurrentDomain.AssemblyLoad event handler in the ResourceContainer , the resource manager hooks the AssemblyLoadContext.Unloading event for all assemblies that have IsCollectible property true. The AssemblyLoadEvent.GetLoadContext(Assembly) would be used to get the context to hook the event handler on from the assembly.
  • When the Unloading event fires, the resource container removes the assembly from its cache
@weltkante
Copy link

probably related to #1700

@grubioe grubioe added this to the 3.1 milestone Sep 5, 2019
@grubioe grubioe added the Enhancement Requested Product code improvement that does NOT require public API changes/additions label Sep 5, 2019
@grubioe grubioe added the rank20 Rank: Priority/rank on a scale of (1..100) label Sep 12, 2019
@grubioe grubioe modified the milestones: 3.1, 5.0 Oct 21, 2019
@vatsan-madhavan vatsan-madhavan removed their assignment Apr 2, 2020
@wall-code-solutions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Requested Product code improvement that does NOT require public API changes/additions rank20 Rank: Priority/rank on a scale of (1..100)
Projects
None yet
Development

No branches or pull requests

7 participants
@weltkante @janvorli @vatsan-madhavan @ryalanms @wall-code-solutions @grubioe and others