AppDomain中创建:解决"无法加载文件或程序集"错误 [英] AppDomain Creation : Resolving "Could not load file or assembly" error
问题描述
这是只是奇怪。这里的code:
This is just weird. Here's the code :
AppDomain newDomain = AppDomain.CreateDomain("newDomain ", null,
new AppDomainSetup
{
ApplicationBase = @"D:\myDLLFolderFullPath\"
});
Assembly a = newDomain.Load("myAssembly");
这将引发无法加载文件或程序的错误。
我检查了我的大会DLL位于指定的文件夹路径下,和大会的名称是正确的。照片
当我复制MyAssembly.dll程序到CurrentDomain的主文件夹,它的工作原理!
它的行为就好像ApplicationBase设定了新的AppDomain完全没有影响,并保持指向当前的AppDomain的应用平台。
This throws the "Could not load file or assembly" error.
I checked my Assembly's dll is located under the specified folder path, and the name of the Assembly is correct.
When I copy myAssembly.dll into the CurrentDomain's main folder, it works !
It behaves as if the ApplicationBase setting for the new AppDomain has absolutely no effect and keep pointing to the Current AppDomain's AppBase.
任何想法?
推荐答案
我不知道,如果.NET允许装载组件,以便在不相对于主可执行文件的路径的路径。
I am not sure if .NET allows loading assemblies from paths that are not relative to the main executable path.
所以,我认为,这是不允许的:
So, I think that this is not allowed:
D:\myExeFolderFullPath\main.exe
D:\myDLLFolderFullPath\Mydll.dll
......,而这应该工作:
...while this should work:
D:\myExeFolderFullPath\main.exe
D:\myExeFolderFullPath\myDLLFolderFullPath\Mydll.dll
更新:
在 mygeneration 项目工作时,我也有类似问题的路径。我发现得到它运行的唯一方法是重新组织我在这个回答中描述的文件夹结构。
I had a similar problem with paths when working on the mygeneration project. The only way I found to get it running was to reorganize the folder structure I described in this answer.
这篇关于AppDomain中创建:解决"无法加载文件或程序集"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!