Cannot replace .NET dll loaded from C++/clr dll and so can’t debug it

  appdomain, c++, clr, dll

I have the following setup

App -> native.dll -> native/clr.dll -> .net.dll

App loads/unloads native.dll before for every call. native.dll in turn uses code like this to load .net.dll:

Assembly^ AssemblyLoader::Load(Object^ sender, ResolveEventArgs^ args) =>
_resolveEventHandler = gcnew ResolveEventHandler(this, &AssemblyLoader::Load);
AppDomain::CurrentDomain->AssemblyResolve += _resolveEventHandler;
AppDomain::CurrentDomain->AssemblyResolve -= _resolveEventHandler;

Appeared that removing the handler doesn’t let .net.dll to unload because CLR keeps DLLs loaded until the app domain hasn’t been unloaded.

So, both native/clr.dll and .net.dll stay in memory forever. But I need to

  1. Debug .net.dll and I can’t replace it with debug version to start debugging.
  2. Remove them after App has finished.

What can I do about it?

Source: Windows Questions C++