Issue with AssemblyLoadContext Unload in .NET

MakesYT Liao 0 Reputation points
2023-12-12T13:33:29.4166667+00:00

I am using AssemblyLoadContext in a .NET WPF project (net8.0-windows10.0.19041.0), and I am encountering a strange issue. If I load the DLL in App.cs, I cannot manually unload it later. However, if I load and unload the DLL by pressing a button after the program starts, it can be unloaded correctly. The code for both cases is almost identical. During uninstallation, I also saw a different symptom through WinDbg. Any idea what could be causing this issue?

Symptom seen through WinDbg during uninstallation:
User's image

Loading the DLL manually later: User's image

Loading the DLL in App.cs (can't unload): User's image

Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Other
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.