Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

c# - Could not load file or assembly but they are loaded

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:

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.

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?

Ps. I have tried the exact same method and dll in a windows forms test app and it was running fine.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Like Pawl Lukasik mentioned in the comments, you should look at the dependencies.

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:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...