【发布时间】:2013-12-16 07:14:08
【问题描述】:
我正在从文件夹中读取 dll 和进程类型。
xxx.dll
xxx.interfaces.dll
当我加载 xxx.dll 并对该程序集调用 GetTypes 时,它会引发异常...
{System.IO.FileNotFoundException: Could not load file or assembly 'xxx.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'xxx.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
=== Pre-bind state information ===
LOG: User = xxx
LOG: DisplayName = xxx.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///<myapp>/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: <myapp>\bin\Debug\Diagrammer.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
}
似乎它试图从启动应用程序路径中获取依赖 dll,而不是正在加载的程序集。当我检查加载和处理程序集 xxx.Interfaces.dll 时,它工作正常。
【问题讨论】:
-
你试过
Assembly.Load和Assembly.LoadFrom吗? -
我使用的是 LoadFile api。感谢您的参考,LoadFrom 正在运行。
-
你应该把它作为答案。这可能对处于我这种情况的其他人有所帮助。我会尝试在此基础上发表我的看法。
标签: c# .net dll reflection .net-assembly