-1

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.

Paweł Łukasik
  • 3,893
  • 1
  • 24
  • 36
Naaman
  • 11
  • 5
  • 4
    take a look at "...or one of its dependencies. The system cannot find the file specified." it might be the dependency loading that failed. – Paweł Łukasik Feb 21 '18 at 13:51
  • I am kinda new to programming and haven't worked with Dll's. Could you give me help and tell me where i could find the dependencies or help me te see the dependencies that are loaded. – Naaman Feb 21 '18 at 14:10
  • @Naaman look at my answer. There is example code to get all referenced assemblies. – Sean Stayns Feb 21 '18 at 14:16
  • This feels like an [XY Problem](http://xyproblem.info/). What is it you are *really* trying to accomplish? Normally, for *managed* assemblies, you set a reference before compiling them, you don't load them using Reflection. Is this some sort of deployment issue? Is the ERP system DLL even written in .NET? – NightOwl888 Feb 21 '18 at 15:44

1 Answers1

0

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();
} 
Sean Stayns
  • 4,082
  • 5
  • 25
  • 35
  • I have tried the code you provided but the problem is that the current executing assembly isn't the one mentioned in the error. – Naaman Feb 21 '18 at 14:24