Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在运行时加载程序集_C#_Dll_Private_Gac_.net Assembly - Fatal编程技术网

C# 在运行时加载程序集

C# 在运行时加载程序集,c#,dll,private,gac,.net-assembly,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

我使用了一个教程(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());
    public string HelloWorld()
    {
        return "1";
    }
项目b:

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());
    public string HelloWorld()
    {
        return "1";
    }
当我执行以下操作时:

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

  • 建设项目b

  • 构建项目a并运行它

  • 我收到一个文本为“1”的消息框,GAC并不总是更新自己


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

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

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