© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago
nicke

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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Forcefully unloading AssemblyLoadContext
C#CC# / help
2y ago
❔ MemoryCache
C#CC# / help
3y ago
Debugger preventing AssemblyLoadContext unload
C#CC# / help
2w ago
AssemblyLoadContext LoadfromAssemblyPath vs LoadFromNativeImagePath
C#CC# / help
2y ago