简体   繁体   English

无法加载文件或程序集,但它们已加载

[英]Could not load file or assembly but they are loaded

I have a project going on witch uses a DLL from an ERP system.我有一个项目正在进行,它使用来自 ERP 系统的 DLL。 The DLL is used to get information from the ERP, like invoices and such. DLL 用于从 ERP 获取信息,如发票等。 The error i am getting is:我得到的错误是:

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.内部异常 1:FileNotFoundException:无法加载文件或程序集“SnelStartGatewayInterface,版本=12.48.37.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。 The system cannot find the file specified.该系统找不到指定的文件。

But in the same window I used 'watch 1' to see the current using assembly's with the method:但是在同一个窗口中,我使用“watch 1”来查看当前使用程序集的方法:

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, Version=12.48.37.0, Culture=neutral, PublicKeyToken=null} System.Reflection.Assembly {System.Reflection.RuntimeAssembly} + [36] {SnelStartGatewayInterface, Version=12.48.37.0, Culture=neutral, PublicKeyToken=null} System.Reflection.Assembly {System.Reflection.RuntimeAssembly}

Why would it return me the error?为什么它会给我返回错误?

Ps.附言。 I have tried the exact same method and dll in a windows forms test app and it was running fine.我在 Windows 窗体测试应用程序中尝试了完全相同的方法和 dll,它运行良好。

Like Pawl Lukasik mentioned in the comments, you should look at the dependencies.就像评论中提到的 Pawl Lukasik 一样,您应该查看依赖项。

To do this, use:为此,请使用:

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.查看所有引用的程序集。

Or with LINQ:或者使用 LINQ:

private List<string> ListReferencedAssemblies()
{
    return Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select(x => x.FullName).ToList();
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM