Appdomain.Load(AssemblyName)引发文件未找到异常

时间:2015-04-08 19:35:17

标签: c# sandbox appdomain

此代码段工作正常:

System.Security.PermissionSet PS = new System.Security.PermissionSet(PermissionState.None);
PS.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, Path));
PS.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
AppDomainSetup ADS = AppDomain.CurrentDomain.SetupInformation;
AppDomain domain = AppDomain.CreateDomain("Pluging", null, ADS, PS, null);
Assembly asm = Assembly.LoadFile(DLLPath); 
domain.Load(asm.FullName);

创建新的AppDomainSetup失败:

System.Security.PermissionSet PS = new System.Security.PermissionSet(PermissionState.None);
PS.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, Path));
PS.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
AppDomainSetup ADS = new AppDomainSetup();
ADS.ApplicationBase= Path;
AppDomain domain = AppDomain.CreateDomain("Pluging", null, ADS, PS, null);
Assembly asm = Assembly.LoadFile(DLLPath); 
domain.Load(asm.FullName);

整个过程都在VS2012开发的asp.net项目中运行。

这是我收到的例外情况:

Could not load file or assembly 'MacroBase, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system 
cannot find the file specified.
你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

问题是我曾经在存储它们之前重命名dll。我仍然不知道周围的工作,但我更改了算法,以便我可以存储和调用与最初编译时名称相同的dll。问题解决了。

更改AppDomainSetup有什么影响?在第一种方案中,asp.net在asp.net项目的bin目录中找到了重命名的dll(带有原始名称)的副本。