c# - .NET 库编辑后无需重新编译程序

标签 c# .net dll

请考虑这种情况:

public class TestType
{
    public string a
    {
        get;
        set;
    }
    public string b
    {
        get;
        set;
    }

    public override string ToString()
    {
        return string.Format("a: \"{0}\"\tb:\"{1}\"", a, b);
    }
}

TestType 类被编译到一个类库中,然后我在这个简单的程序中使用它:

    static void Main(string[] args)
    {
        TestType tP = new TestType();
        tP.a = "a";
        tP.b = "b";
        Console.WriteLine(tP.ToString());
        Console.ReadKey(true);
    }

显然它有效(正确执行没有错误)。

输出:a: "a"b:"b"

然后我像这样编辑库中的类:

public class TestType
{
    public string a
    {
        get;
        set;
    }
    public string b
    {
        get;
        set;
    }
    public string c
    {
        get;
        set;
    }

    public override string ToString()
    {
        return string.Format("a: \"{0}\"\tb:\"{1}\"\tc:\"{2}\"", a, b, c);
    }
}

我只重新编译库并重新运行程序(不重新编译)。 现在我预计程序会崩溃,因为它不知道类的更改,但它可以工作。

输出:a: "a"b:"b"c:""

如果类型与它知道的类型不同,它如何工作?

最佳答案

.NET DLL 具有一定程度的向后兼容性。添加字段不是 binary-breaking change

关于c# - .NET 库编辑后无需重新编译程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29072616/

相关文章:

.net - 在没有 NodeJs 和 JSPM 的情况下运行 Aurelia 框架

.net - 如何获得事件的反馈?

python - 使用 CTypes 时检测从 Windows DLL 调用 Python 脚本

c++ - 绕行函数在 printf 上崩溃

windows - 如何调试regsvr32编译后DLL注册异常?

c# - ASP.NET MVC3 升级 - "Attempt by method [whatever] to access method System.Web.Mvc.Controller.View(...) failed"

c# - 纹理/模型在远处闪烁 (3D)

c# - 服务器和客户端之间通过TCP异步传输数据

c# - HttpWebRequest 返回 "(403) Forbidden"错误

.net - 为什么是 "Evaluation of lambda expressions is not valid in the debugger"?