【问题标题】:Load an assembly at runtime在运行时加载程序集
【发布时间】:2012-08-02 18:30:35
【问题描述】:

我使用教程(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 并运行它

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

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

【问题讨论】:

  • 这似乎是错误的。您不应该在同一进程中安装到 GAC。
  • 很奇怪 GacRemove() 采用文件系统路径。它应该采用程序集名称,包括版本。嗯,这是一种失败模式。

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


【解决方案1】:

首先,更改 GAC 不太可能帮助已在运行的进程。在这种特定情况下,请注意 JIT 在每个方法方法执行之前发生。这意味着 MyAssembly1 在删除/安装步骤之前已解决并加载。但是,这并不能改变这样一个事实,即这不太可能是一个好方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 2018-04-24
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2010-10-05
    相关资源
    最近更新 更多