.NET DLL热插拔,不重新启动应用程序 [英] .NET dll hot swap, no application restart

查看:325
本文介绍了.NET DLL热插拔,不重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您在.NET(C#)中具有以下情况:

Suppose that you have the following situation in .NET (C#):

namespace MyDll
{
    public class MyClass
    {
        public string GetValue()
        {
            return "wrong value";
        }
    }
}

此代码被编译为dll说MyDll.Dll。

this code goes compiled into a dll say, MyDll.Dll.

然后,您有一个名为MyApplication.exe的应用程序,该应用程序使用MyDll.dll作为引用,创建了MyClass类的实例并调用了方法GetValue:

Then you have an application called MyApplication.exe that, using MyDll.dll as reference, creates an instance of the class MyClass and calls the method GetValue:

MyClass instance = new MyClass();
instance.GetValue();

一旦您意识到MyClass.GetValue()的当前实现是错误的,有什么办法可以解决这样的方法MyClass.GetValue()

Once you realize that the current implementation of MyClass.GetValue() is wrong is there any way to fix the method MyClass.GetValue() like this

namespace MyDll
{
    public class MyClass
    {
        public string GetValue()
        {
            return "correct value";
        }
    }
}

并热交换生成的MyDll .dll,而无需重新启动MyApplication.exe ???

and HOT swapping the resulting MyDll.dll, without restarting MyApplication.exe???

在stackoverflow和google中提出的所有解决方案都无法正常工作,因为即使MyDll.dll已加载到新的AppDomain上为此创建的,当我卸载调用时

All solutions proposed in stackoverflow and in google fail to work because, even if MyDll.dll is loaded on a new AppDomain created for that purpose, when I unload calling

AppDomain.Unload(anoterAppDomainJustForMyDll);

它返回时没有错误,但是如果我尝试用更正后的内容覆盖原始MyDll.dll(而MyApplication.exe仍在运行时)出现错误由于另一个进程正在使用dll,因此无法覆盖...。

it returns without error, but if I try to overwrite the original MyDll.dll with the corrected one (while MyApplication.exe is still running) I get an error "impossible to overwrite because the dll in use by another process"....

推荐答案

我自己关闭了问题:请参阅 codeplex

Question is closed by myself: please refer to article in codeplex

对我来说,能够在不重新启动应用程序的情况下热交换新的dll非常重要,正如本文所建议的,可以做到的,因为这是与应用程序本身一起完成的。我以前的尝试失败的原因是我试图从外部(在这种情况下为资源管理器)覆盖目标dll。但是,如果覆盖按照建议的解决方案那样完成,则从应用程序本身开始,它可以按预期工作。

To me it was important to be able to hot swap the new dll without rebooting the application, and as the article proposes, this can be done, as this is done from withing the application itself. The reason why my previous attemps were failing was that I tried to overwrite the target dll from outside (in explorer in this case). But if the overwriting is done like in the proposed solution, from the application itself, it works as expected.

在应用程序端,我需要更多一点来定义目录可以在其中部署可版本控制的ddls,但这对我来说完全可以接受。

I will need a little bit more on application side to define directories where versionable ddls can be deployed, but this is perfectly acceptable to me.

这篇关于.NET DLL热插拔,不重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆