How can I force reload assembly in Unity Editor

For automatic modify my code, I use Mono cecil to add some IL code in “Library/ScriptAssembies/Assembly-CSharp.dll”, once my inject process complete, the Unity Editor load it and works well, but if I want to change c# code and recompile it, it doesn’t work again. No matter how I reload or inject the newer assembly, the editor always use the old assembly that I first injected. In an odd way, if I delete Assembly-CSharp.dll, the editor won’t play and notice “Loading script assembly “Library/ScriptAssemblies/Assembly-CSharp.dll” failed!” , but if I modify C# code and recompile it, the Editor will work with the old assembly. How it works?

Is there some way that I can force reload Assembly-CSharp.dll?

By the way, after I use mono cecil, Unity can’t provide any debug info, just like line number and filename, could I inject IL code without missing debug info?

Finally, could I recompile C# code by using some API?

I use Unity 5.6.2p4 on Windows 10.

I’m waiting for the solution, thanks

1 Like

For conserving debugging info you should convert debugging symbols too.
It should be something like this

readerParameters.SymbolReaderProvider = new MdbReaderProvider();
writerParameters.SymbolWriterProvider = new MdbWriterProvider();

Haven’t found a way to reload assemblies without play/stop routine