C# 在运行时加载程序集
我使用了一个教程(http://support.microsoft.com/kb/837908,方法1)生成两个项目。项目a引用了项目b 项目a: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
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并在项目a上查看它的最简单方法是什么?首先,更改GAC不太可能帮助已经运行的流程。在这种特定情况下,请注意,JIT是在执行方法之前按照方法进行的。这意味着MyAssembly1在拆卸/安装步骤之前已解析并加载。然而,这并不能改变这样一个事实,即这不太可能是一个好方法。这似乎是错误的。您不应该在同一进程中安装到GAC。GacRemove()采用文件系统路径,这相当奇怪。它应该采用程序集名称,包括版本。这是一种失败模式。