假设您在.NET(C#)中具有以下情况:
namespace MyDll
{
public class MyClass
{
public string GetValue()
{
return "wrong value";
}
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码编译成一个dll说,MyDll.Dll.
然后你有一个名为MyApplication.exe的应用程序,使用MyDll.dll作为参考,创建一个MyClass类的实例并调用方法GetValue:
MyClass instance = new MyClass();
instance.GetValue();
Run Code Online (Sandbox Code Playgroud)
一旦你意识到MyClass.GetValue()的当前实现是错误的,有什么办法可以修复MyClass.GetValue()这样的方法
namespace MyDll
{
public class MyClass
{
public string GetValue()
{
return "correct value";
}
}
}
Run Code Online (Sandbox Code Playgroud)
和HOT交换生成的MyDll.dll,而不重新启动MyApplication.exe ???
stackoverflow和google中提出的所有解决方案都无法正常工作,因为即使MyDll.dll加载到为此目的创建的新AppDomain上,当我卸载调用时也是如此
AppDomain.Unload(anoterAppDomainJustForMyDll);
Run Code Online (Sandbox Code Playgroud)
它返回没有错误,但如果我尝试用更正的一个覆盖原始的MyDll.dll(当MyApplication.exe仍在运行时),我收到错误"无法覆盖因为另一个进程正在使用的dll"....