Unity is using files loaded by Assembly.LoadFrom even after the game simulation is terminated

I have a game that loads .dll files into the runtime with Assembly.LoadFrom(). When I have terminated the game simulation in the editor, Unity is still using these files as I can’t delete, rename or move them. Is there a way of stopping this from happening?

Dll loading code:

foreach (var file in dir.GetFiles())
if (file.Name.EndsWith (“.dll”))
Assembly ass = Assembly.LoadFrom (file.FullName);

Based on this page: How to: Load and unload assemblies - .NET | Microsoft Learn
it seems that you need to load your assemblies into a custom AppDomain and then unload the AppDomain.
I don’t know if this will work in Unity, but it is worth a try.
I suggest calling the unload code from some OnDestroy() or OnDisable() function

As far as i know, Unity is already loading all scripting assemblies into a custom “scripting” app domain that gets unloaded as you exit play mode.