无法加载文件或程序集,但它们已加载 [英] Could not load file or assembly but they are loaded
问题描述
我有一个正在进行的项目,它使用了ERP系统中的DLL.DLL用于从ERP获取信息,例如发票等.我得到的错误是:
I have a project going on witch uses a DLL from an ERP system. The DLL is used to get information from the ERP, like invoices and such. The error i am getting is:
内部异常1:FileNotFoundException:无法加载文件或程序集'SnelStartGatewayInterface,Version = 12.48.37.0,文化=中性,PublicKeyToken =空"或其依赖项之一.这系统找不到指定的文件.
Inner Exception 1: FileNotFoundException: Could not load file or assembly 'SnelStartGatewayInterface, Version=12.48.37.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
但是在同一窗口中,我使用手表1"通过以下方法使用程序集查看当前情况:
But in the same window I used 'watch 1' to see the current using assembly's with the method:
AppDomain.CurrentDomain.GetAssemblies()
它返回几个程序集.这是一个加载的错误,与错误中显示的完全相同:
It returns a couple of assembly's. This is the one loaded in and exactly the same as seen in the error:
+ [36] {SnelStartGatewayInterface,版本= 12.48.37.0,Culture =中性,PublicKeyToken =空} System.Reflection.Assembly{System.Reflection.RuntimeAssembly}
+ [36] {SnelStartGatewayInterface, Version=12.48.37.0, Culture=neutral, PublicKeyToken=null} System.Reflection.Assembly {System.Reflection.RuntimeAssembly}
为什么会返回错误?
Ps.我已经在Windows窗体测试应用程序中尝试了完全相同的方法和dll,并且运行良好.
Ps. I have tried the exact same method and dll in a windows forms test app and it was running fine.
推荐答案
就像注释中提到的Pawl Lukasik一样,您应该查看依赖项.
Like Pawl Lukasik mentioned in the comments, you should look at the dependencies.
为此,请使用:
private List<string> ListReferencedAssemblies()
{
List<string> refList = new List<string>();
var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
foreach (var assembly in assemblies)
{
refList.Add(assembly.Name);
}
return refList;
}
查看所有引用的程序集.
to see all referenced assemblies.
或使用LINQ:
private List<string> ListReferencedAssemblies()
{
return Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select(x => x.FullName).ToList();
}
这篇关于无法加载文件或程序集,但它们已加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!