本文介绍了无法加载文件或程序集,但它们已加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目正在进行,它使用来自 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,版本 = 12.48.37.0,Culture=neutral, PublicKeyToken=null' 或其依赖项之一.这系统找不到指定的文件.

但是在同一个窗口中,我使用watch 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, Version=12.48.37.0, Culture=neutral, PublicKeyToken=null} System.Reflection.Assembly{System.Reflection.RuntimeAssembly}

为什么会返回错误信息?

Why would it return me the error?

附言.我在 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();
}

这篇关于无法加载文件或程序集,但它们已加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 10:58