如何从 GAC 卸载程序集?
我正在尝试对特定产品运行自动化测试。 测试包括将产品安装到硬盘上的不同位置,然后对其执行一些操作,然后关闭应用程序。
启动该进程的代码如下所示:
using (Process process = new Process())
{
process.StartInfo.FileName = "C:\mylocation\myapp.exe";
process.Start();
}
在连续执行测试时,当应用程序的安装位置发生变化时,我从上面的代码中得到一个异常:
API 限制:程序集 '文件:///C:\alternate_location\myapp.exe' 已经从不同的地方加载了 地点。它无法从 同一地点内的新位置 应用程序域。
因此,测试无法连续运行。
可以采取什么措施来克服这个问题?我是否可以从 GAC 卸载程序集?
我可以在我的测试应用程序中做一些事情来克服这个问题,或者我正在测试的应用程序中是否必须进行某些更改?
I am trying to run automated tests on a particular product.
The test consists of installing the product into different locations on the hard drive and then performing some operations on it and then closing the application.
The code that launches the process looks like this:
using (Process process = new Process())
{
process.StartInfo.FileName = "C:\mylocation\myapp.exe";
process.Start();
}
While executing the tests continuously, when the install location of the application changes, I get an exception from the above code that says:
API restriction: The assembly
'file:///C:\alternate_location\myapp.exe'
has already loaded from a different
location. It cannot be loaded from a
new location within the same
appdomain.
The tests cannot be run continuously because of this.
What can be done to overcome this? Is there anyway I can unload assemblies form the GAC?
Can I do something in my test application to overcome this OR does something have to be changed in the application that I am testing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一旦加载,就无法从应用程序域卸载程序集。但是您可以创建一个新的应用程序域(AppDomain 类) ,加载其中的程序集,使用它们,然后卸载域。请参阅此处:AppDomain 使用的好示例
You can't unload assemblies from an application domain once loaded. But you could create a new application domain (AppDomain class), load the assemblies within it, use them, then unload the domain. See here: Good example of use of AppDomain
向 GAC 添加某些内容并不是组件定义的固有部分 - 它通常由安装程序等完成。
gacutil 工具可用于从 GAC 中删除您的工具。在 1.1 中,它位于 Framework 目录中。在较新的版本中,它位于 SDK 中,例如
C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin
Adding something to the GAC is not an intrinsic part of the component's definition - it's generally done by an installer etc.
The gacutil tool can be used to remove your tool from the GAC. In 1.1, it was in the Framework dir. In newer versions, its in the SDK, e.g.,
C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin
您能为我们提供更多信息吗?我无法重现这个错误。
Process.Start 应该创建一个具有自己的 AppDomain 的新进程。
在我的计算机上,我创建了一个项目 Harness,其中包含对 DoNothing 的项目引用(强签名程序集)和对 LaodDoNothing 的项目引用(其中引用了 c:\DoNothing.exe)。我从 Harness.Main 粘贴了下面的代码,并将调试输出作为内联注释。后缀为 unsigned 的 exes 是没有签名的。
Could you provide more information for us? I haven't been able to reproduce this error.
Process.Start should create a new process with its own AppDomain.
On my machine I created a project Harness which has a project reference to DoNothing which is a strongly signed assembly and a project reference to LaodDoNothing which has a reference to c:\DoNothing.exe. I've pasted the code below from Harness.Main with debug outputs as inline comments. The exes suffixed with unsigned are not signed.