-
I am trying to establish for a fact whether my dynamically loaded dll has been unloaded. My use case - there are user defined C# scripts that are used in a data grid columns in .NET 7 WPF app. A user can make changes and then compile new version to a different dll. At this point I need to unload previous version of that dll. I seems to not able to unload it correctly. I watered down the test to the following: I am using this as the basis for my test code: https://learn.microsoft.com/en-us/dotnet/standard/assembly/unloadability It works in one case but breaks in another. I am not sure whether I am using it wrong or it didnt unload in second case. DLL is loaded in custom If I press button1 the However if I split RunTest to 2 stages - Having said that if I look in VS "Modules" window - there is So my question here - do I use weak ref incorrectly and dll is actually unloaded.. Or dll is not unloaded and my understanding of what Modules window shows is incorrect.. In either way - is there a bulletproof method to check whether the dll has been unloaded?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@janvorli could you please take a look (I'm leaving for vacation...) |
Beta Was this translation helpful? Give feedback.
-
@maxima120 the primary issue here is that for the split case you keep the |
Beta Was this translation helpful? Give feedback.
-
Yes, you can create a weak reference to the assembly you get from the |
Beta Was this translation helpful? Give feedback.
@maxima120 the primary issue here is that for the split case you keep the
MyAssemblyLoader
reference in thealc
variable after calling theUnload
method. Unloading depends on GC collecting theAssemblyLoadContext
, all the assemblies, instances of data types from those assemblies etc. Until all of these are collected, the unload cannot be completed. I think that if you assigned null to it right after calling theTestUnload22
inButton2_Click
, it would work (unless I've missed some other issue).