自定义AppDomain和PrivateBinPath [英] Custom AppDomain and PrivateBinPath

查看:213
本文介绍了自定义AppDomain和PrivateBinPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#4.0和控制台应用程序进行测试,以下代码确实给出了例外.

I'm using c# 4.0 and a console application just for testing, the following code does gives an exception.

AppDomainSetup appSetup = new AppDomainSetup()
{
    ApplicationName = "PluginsDomain",
    ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
    PrivateBinPath = @"Plugins",
    ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
};

AppDomain appDomain = AppDomain.CreateDomain("PluginsDomain", null, appSetup);

AssemblyName assemblyName = AssemblyName.GetAssemblyName(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins", "sample.dll"));

Assembly assembly = appDomain.Load(assemblyName); //This gives an exception of File not found

AppDomain.Unload(appDomain);

在创建的AppDomain上使用 Load 时,我始终收到找不到文件"异常.

I keep getting File not found exception when using Load on my created AppDomain.

谢谢.

推荐答案

我想我想出了为什么会这样,那是因为即使您将程序集加载到其他应用程序域中,当前域也需要加载程序集,当前域需要了解并加载它,这是因为.NET是如何设计的.

I think i'v figured out why this happens, thats because the current domain needs to load the assembly too even if your loading the assembly in a diffrent app domain, the current domain needs to know about it and load it, thats because how the .NET was designed.

在此处查看详细信息.

http://msdn.microsoft.com/en-us/library/36az8x58.aspx

,当我检查融合日志时,我发现新创建的应用程序域已成功能够从专用bin路径加载程序集,以及为什么仍会收到找不到文件"异常的原因,因为异常最初属于当前应用程序域.

and when i checked the fusion logs, i found that the newly created app domain was successfully able to load the assembly from the private bin path, and the reason why you still get the exception of "File not found", because this exception belongs originally to the current app domain.

这意味着,如果您将程序集复制到当前应用程序路径中或当前域正在探测的路径中,则会发现您可以将程序集加载到自定义域中.

that means if you copied the assembly in current application path or to the path where the current domain is probing, you will find that you can load the assembly into your custom domain.

希望有帮助.

这篇关于自定义AppDomain和PrivateBinPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆