如何从 GAC 卸载程序集?

发布于 2024-08-10 18:01:36 字数 592 浏览 7 评论 0原文

我正在尝试对特定产品运行自动化测试。 测试包括将产品安装到硬盘上的不同位置,然后对其执行一些操作,然后关闭应用程序。

启动该进程的代码如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迎风吟唱 2024-08-17 18:01:36

一旦加载,就无法从应用程序域卸载程序集。但是您可以创建一个新的应用程序域(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

自在安然 2024-08-17 18:01:36

向 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

治碍 2024-08-17 18:01:36

您能为我们提供更多信息吗?我无法重现这个错误。

Process.Start 应该创建一个具有自己的 AppDomain 的新进程。

在我的计算机上,我创建了一个项目 Harness,其中包含对 DoNothing 的项目引用(强签名程序集)和对 LaodDoNothing 的项目引用(其中引用了 c:\DoNothing.exe)。我从 Harness.Main 粘贴了下面的代码,并将调试输出作为内联注释。后缀为 unsigned 的 exes 是没有签名的。

//debug outputs when Main is jitted:'Harness.vshost.exe' (Managed): Loaded 'c:\project\DoNothing\Harness\bin\Debug\DoNothing.exe', Symbols loaded.
//debug outputs when Main is jitted:'Harness.vshost.exe' (Managed): Loaded 'c:\project\DoNothing\Harness\bin\Debug\LoadDoNothing.exe', Symbols loaded.

ZaZaZa.Main();
LoadDoNothing.Program.Main();
using (Process process = new Process())
{
    process.StartInfo.FileName = @"C:\donothingunsigned.exe";
    process.Start(); //debug outputs The thread 0x17f0 has exited with code 0 (0x0).  No assemblies loads are logged to debug because this is a separate process.


}

using (Process process = new Process())
{
    process.StartInfo.FileName = @"C:\3\donothingunsigned2.exe";
    process.Start(); //Debug outputs The thread 0x1014 has exited with code 0 (0x0). No assemblies loads are logged to debug because this is a separate process.
}
AppDomain.CurrentDomain.ExecuteAssembly(@"C:\donothingunsigned.exe"); //debug outputs 'Harness.vshost.exe' (Managed): Loaded 'C:\donothingunsigned.exe'
AppDomain.CurrentDomain.ExecuteAssembly(@"C:\3\donothingunsigned2.exe"); //no debug output because the loader realizes this assembly has already been loaded and uses that.

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.

//debug outputs when Main is jitted:'Harness.vshost.exe' (Managed): Loaded 'c:\project\DoNothing\Harness\bin\Debug\DoNothing.exe', Symbols loaded.
//debug outputs when Main is jitted:'Harness.vshost.exe' (Managed): Loaded 'c:\project\DoNothing\Harness\bin\Debug\LoadDoNothing.exe', Symbols loaded.

ZaZaZa.Main();
LoadDoNothing.Program.Main();
using (Process process = new Process())
{
    process.StartInfo.FileName = @"C:\donothingunsigned.exe";
    process.Start(); //debug outputs The thread 0x17f0 has exited with code 0 (0x0).  No assemblies loads are logged to debug because this is a separate process.


}

using (Process process = new Process())
{
    process.StartInfo.FileName = @"C:\3\donothingunsigned2.exe";
    process.Start(); //Debug outputs The thread 0x1014 has exited with code 0 (0x0). No assemblies loads are logged to debug because this is a separate process.
}
AppDomain.CurrentDomain.ExecuteAssembly(@"C:\donothingunsigned.exe"); //debug outputs 'Harness.vshost.exe' (Managed): Loaded 'C:\donothingunsigned.exe'
AppDomain.CurrentDomain.ExecuteAssembly(@"C:\3\donothingunsigned2.exe"); //no debug output because the loader realizes this assembly has already been loaded and uses that.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文