【发布时间】:2015-10-05 05:54:41
【问题描述】:
我已经搜索了这个地狱,但是当文件明确存在并且可以使用 File.ReadAllBytes 打开时,我无法完全找出为什么我会收到 FileNotFoundException
这是我当前的代码:
AppDomainSetup domainInfo = new AppDomainSetup();
domainInfo.ApplicationBase = PluginDirectory;
Evidence adEvidence = AppDomain.CurrentDomain.Evidence;
AppDomain pluginDomain = AppDomain.CreateDomain("pluginDomain", adEvidence, domainInfo);
foreach (FileInfo file in files)
{
if (m_AssemblyIgnoreList.Contains(file.Name))
continue;
byte[] assemblyBytes = File.ReadAllBytes(file.FullName);
//Assembly plugin = Assembly.LoadFrom(file.FullName);
Assembly plugin = pluginDomain.Load(assemblyBytes);
LoadPlayerEvents(plugin);
}
AppDomain.Unload(pluginDomain);
我正在尝试从插件文件夹中加载所有 .dll 文件,并加载一堆属性类型和函数。
当我使用 Assembly.LoadFrom(file.FullName) 时,属性类型和函数的加载工作文件。但是,pluginDomain.Load(assemblyBytes) 会导致以下异常:
FileNotFoundException: Could not load file or assembly 'Example Mod, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
它肯定会找到指定的文件,因为 File.ReadAllBytes 可以完美运行,因为异常会显示我要加载的程序集的全名。因此我得出结论,它无法加载依赖项。
所有依赖项都已加载到 CurrentDomain。虽然,即使我将这些依赖项放在 .dll 旁边(无论如何,这都会发生在所述 .dll 的构建期间),也会产生相同的异常。
当文件明确存在时,为什么我会收到此异常?
【问题讨论】:
-
您可以运行 Process Monitor 来检查您的应用程序在哪些位置搜索 dll,也许您知道为什么它没有在您想要的位置搜索。
标签: c# dll plugins .net-assembly appdomain