© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
21 replies
Pdawg

Forcefully unloading AssemblyLoadContext

I'm building a plugin system for my WinUI 3 C# app. Currently, the plugin system uses an AssemblyLoadContext for each plugin, but I want to be able to unload the plugins on demand. ALC.Unload places the assembly in line for GC collection, but it doesn't actually unload the code until all event handlers are disconnected, and all running threads suspend. While this is usually a good thing, I need to be able to control the plugins on demand. In an environment like this, someone could easily create a malicious block of code that continues to run in the background without the user ever noticing; or, poorly written code could continue to run even if it wasn't intended to do so. Each plugin has a Shutdown method, and that is always called before the unload is requested, so plugins can gracefully shutdown and save data or do whatever else they need to do to ensure that user data isn't lost.

So, is there a way that I can force an ALC to unload the plugin right there and then instead of waiting for it to finish up what it's doing?
image.png
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

AssemblyLoadContext not unloading if system.runtime.caching MemoryCache used inside ALC.
C#CC# / help
4y ago
Debugger preventing AssemblyLoadContext unload
C#CC# / help
2w ago
AssemblyLoadContext LoadfromAssemblyPath vs LoadFromNativeImagePath
C#CC# / help
2y ago
AssemblyLoadContext Error - .NET 8.0
C#CC# / help
2y ago