Can't replace DLL file after running.

I’ve asked this question before, but due to the nature of these stack overflow-like forums, any modifications to the question do little to bring it to anyone’s attention, and making substantial changes to a question are frowned upon.

So, I’ll try asking this in a different way.

I need to replace a plugin DLL frequently, as it is part of the testing process. I build the DLL with MSC, and run it with a C# script in Unity. The problem is, after it is used only once by a script, the module remains in use until the editor is restarted (that is, I cannot delete or replace the file, either manually or through another program).

This tells me that the C# runtime that Unity is using is not releasing references to modules that are not in use after scene scripts have stopped running.

I wrote a little test module that produces a message box when DllMain gets called with DLL_PROCESS_DETACH. After I run and then stop a script that loads it, the message box does not pop up until I close the editor.

I understand that the runtime dynamically loads the script and its dependencies while the editor is running, and playing/stopping the game does not necessarily mean that any modules loaded by scripts are unloaded.

MY QUESTIONS ARE:

How can I force the editor to unload a module without having to restart it?

Is there a list of loaded modules somewhere I can access that would allow me to force an unload?

This happens all the time if you have placed your DLL in the “Assets/Plugins” folder. If the DLL is not truly a plugin but just an assembly, placing it into any other folder will fix this issue (almost - it will still happen from time to time, but much more rarely).
If instead it’s a true plugin, I apologize for the useless answer :stuck_out_tongue:

Create a method to manually stop the threads and release all the resources.

Invoke this method in OnApplicationQuit.

This may work! :slight_smile:

Seven years later nothing has been done to address this issue.

It’s impossible to iterate on testing plugins, why this is not addressed?

Gah this problem is making development borderline impossible - have to restart unity editor after every code tweak! No solutions yet?