AssemblyLoadContext not unloading if system.runtime.caching MemoryCache used inside ALC.
Our use cases allows third parties to create plugins, so we do not have full control of how they are implemented.
When using AppDomains in .net framework MemoryCache was disposed internally by the MemoryCache implementation when AppDomain unloaded see: https://github.com/microsoft/referencesource/blob/dae14279dd0672adead5de00ac8f117dcf74c184/System.Runtime.Caching/System/Caching/MemoryCache.cs#L185
Problem is the unload event is not implemented in .NET 6 for AppDomains.
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs#L67
Is there any other way than fixing the plugin code to listen for AssemblyLoadContext.Unloading event and Dispose of the MemoryCache?
0 Replies