Search code examples
c#importdlldllimporttypeloadexception

TypeLoadException when loading a dll


I have a behaviour when importing a C# dll into another C# solution.
The dll I'm trying to import is a class library that I've previously implemented for another project and in which I made some improvements during time. The dll compiles just fine and after I've imported it into the new solution the classes and methods are found by intellisense.

The problem is when I run the project in which the dll is imported and a TypeLoadException is throw (the message is something like "Unable to load type 'xyz' from assembly ...".

I've already tried to delete the .vs folder and clean and rebuild the solution (both). I have also tried to decompile the actual dll to seeif there is something strange, but the classes and methods are actually there.


Solution

  • Thanks all.
    I was importing the same dll on 2 different projects of the new solution and (I still don't know why) one project had an old reference to the dll (even if the reference was directly to the file).
    Even if the method existed in the new reference, visual studio was loading the old one.

    Removing the old reference and adding it again solved the problem.