在运行时加载程序集

时间:2012-08-05 14:29:06

标签: c# dll private gac .net-assembly

我使用了一个教程(http://support.microsoft.com/kb/837908,方法1)来生成两个项目。项目a引用项目b。

投射a:

new System.EnterpriseServices.Internal.Publish().GacRemove(string.Format(@"C:\Users\[me]\Documents\Visual Studio 2010\Projects\MyAssembly1\MyAssembly1\bin\Debug\MyAssembly1.dll"));
new System.EnterpriseServices.Internal.Publish().GacInstall(string.Format(@"C:\Users\[me]\Documents\Visual Studio 2010\Projects\MyAssembly1\MyAssembly1\bin\Debug\MyAssembly1.dll"));
MyAssembly1.Class1 obj1 = new MyAssembly1.Class1();
MessageBox.Show(obj1.HelloWorld());

项目b:

    public string HelloWorld()
    {
        return "1";
    }

当我执行以下操作时:

  1. 将项目b中的“HelloWorld”方法更改为“2”(而不是“1”)。

  2. 构建项目b

  3. 构建项目a并运行它

  4. 我收到带有“1”的消息框作为文本,而GAC并不总是自行更新。

    更新项目b并在项目a上看到它的最简单方法是什么?

1 个答案:

答案 0 :(得分:0)

首先,更改GAC不太可能有助于已经运行的流程。在这种特定情况下,请注意JIT在执行方法之前按方法进行。这意味着在删除/安装步骤之前解析并加载MyAssembly1。然而,这并没有改变这一事实,即这不太可能成为一种好方法。