Typeloadexception Says 'No Implementation', But It Is Implemented

TypeLoadException says 'no implementation', but it is implemented

NOTE - If this answer doesn't help you, please take the time to scroll down through the other answers that people have added since.

Short answer

This can happen if you add a method to an interface in one assembly, and then to an implementing class in another assembly, but you rebuild the implementing assembly without referencing the new version of the interface assembly.

In this case, DummyItem implements an interface from another assembly. The SetShort method was recently added to both the interface and the DummyItem - but the assembly containing DummyItem was rebuilt referencing the previous version of the interface assembly. So the SetShort method is effectively there, but without the magic sauce linking it to the equivalent method in the interface.

Long answer

If you want to try reproducing this, try the following:

  1. Create a class library project: InterfaceDef, add just one class, and build:

    public interface IInterface
    {
    string GetString(string key);
    //short GetShort(string key);
    }
  2. Create a second class library project: Implementation (with separate solution), copy InterfaceDef.dll into project directory and add as file reference, add just one class, and build:

    public class ImplementingClass : IInterface
    {
    #region IInterface Members
    public string GetString(string key)
    {
    return "hello world";
    }

    //public short GetShort(string key)
    //{
    // return 1;
    //}
    #endregion
    }
  3. Create a third, console project: ClientCode, copy the two dlls into the project directory, add file references, and add the following code into the Main method:

     IInterface test = new ImplementingClass();
    string s = test.GetString("dummykey");
    Console.WriteLine(s);
    Console.ReadKey();
  4. Run the code once, the console says "hello world"

  5. Uncomment the code in the two dll projects and rebuild - copy the two dlls back into the ClientCode project, rebuild and try running again. TypeLoadException occurs when trying to instantiate the ImplementingClass.

TypeLoadException says 'no implementation', but it is implemented

NOTE - If this answer doesn't help you, please take the time to scroll down through the other answers that people have added since.

Short answer

This can happen if you add a method to an interface in one assembly, and then to an implementing class in another assembly, but you rebuild the implementing assembly without referencing the new version of the interface assembly.

In this case, DummyItem implements an interface from another assembly. The SetShort method was recently added to both the interface and the DummyItem - but the assembly containing DummyItem was rebuilt referencing the previous version of the interface assembly. So the SetShort method is effectively there, but without the magic sauce linking it to the equivalent method in the interface.

Long answer

If you want to try reproducing this, try the following:

  1. Create a class library project: InterfaceDef, add just one class, and build:

    public interface IInterface
    {
    string GetString(string key);
    //short GetShort(string key);
    }
  2. Create a second class library project: Implementation (with separate solution), copy InterfaceDef.dll into project directory and add as file reference, add just one class, and build:

    public class ImplementingClass : IInterface
    {
    #region IInterface Members
    public string GetString(string key)
    {
    return "hello world";
    }

    //public short GetShort(string key)
    //{
    // return 1;
    //}
    #endregion
    }
  3. Create a third, console project: ClientCode, copy the two dlls into the project directory, add file references, and add the following code into the Main method:

     IInterface test = new ImplementingClass();
    string s = test.GetString("dummykey");
    Console.WriteLine(s);
    Console.ReadKey();
  4. Run the code once, the console says "hello world"

  5. Uncomment the code in the two dll projects and rebuild - copy the two dlls back into the ClientCode project, rebuild and try running again. TypeLoadException occurs when trying to instantiate the ImplementingClass.

Method does not have an implementation when loading assemblies into a new AppDomain in ReflectionOnly mode

Answering my own question:

When the exception was thrown, I went up the stack trace and listed the assemblies loaded in the child AppDomain created:

AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies()
{System.Reflection.RuntimeAssembly[15]}
...
[13]: {System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
[14]: {System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}

and noticed the two versions of System.Data assembly. The method in question has a parameter of type System.Data.IDbTransaction.

First one was referenced in a project targeting .NET framework 3.5. After changing it to 4.0 everything works fine.

What a stupid problem ...

System.TypeLoadException: Method 'get_xxx' does not have an implementation

OK, so bizarrely adding a reference to App.Web in Api.Web and removing it again has solved the issue.

I have no idea why, but it did.

I changed the version of App.Web to 1.0.0.1 and the error was still showing 1.0.0.0, which is what prompted me to do it.

I wish there was a more reasonable explanation but there isn't. Such an infuriating issue i'm just glad to be done with it.

Best of luck to anyone else who experiences this, my thought's are with you

System.TypeLoadException - Method get_*** in type *** from assembly *** does not have an implementation when it does?

I've got the same error message in the following situation: A.dll depends on B.dll, B.dll depends on C.dll and C.dll is not found.
In my case A.dll contains a class C2 derived from abstract class C1 located in the same assembly and in the same dll - A.dll. C1 is derived from C0 class from B.dll. C0 has abstract property with abstract getter method, C1 has an implementation of this property but the matter is that return type of the property's getter is defined in the absent library C.dll.
Finaly, it leads to the error message "Method 'get_Prop' in type 'C2' from assembly 'A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxx' does not have an implementation."
which is rather irrelevant in this situation.
In short the source code looks like this:

C.dll:

namespace C {
public enum PropType {V1 = 0, V2 = 1, ...}
}

B.dll:

using C;
namespace B {
public abstract class C0 {
...
public abstract C.PropType Prop {get;}
}
}

A.dll:

using C;
using B;
namespace A {
public abstract class C1 : B.C0 {
...
// Getter implementation
public override C.PropType Prop { get {return C.PropType.V1;}}
}
}

using C;
using B;
namespace A {
// Class implementation
public class C2 : C1 {
...
}
}

So the solution is to add C.dll to the installation.

TypeLoadException: Method 'Create' in type ... does not have an implementation (Error Below)

Basically, the error message means that Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory type has a mention of Create method in your code/library, but it is unable to find it as there is a wrong version's reference of the nuget package in which Create method is not present.

Please note that all the following packages should be of same version:

  • Microsoft.EntityFrameworkCore.Tools
  • Microsoft.EntityFrameworkCore
  • Microsoft.AspNetCore.Identity.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.SqlServer

For example, all of these can be of 3.1.4 version. Check out exact same issue around this: I get an error when I add migration using Entity Framework Core

If this does not work, you might want to check out this solution.



Related Topics



Leave a reply



Submit