I've got a very weird bug on our test machine. The error is:
System.TypeLoadException: Method 'SetShort' in type 'DummyItem' from assembly 'ActiveViewers (...)' does not have an implementation.
I just can't understand why. SetShort
is there in the DummyItem
class, and I've even recompiled a version with writes to the event log just to make sure that it's not a deployment/versioning issue. The weird thing is that the calling code doesn't even call the SetShort
method.
In addition to what the asker's own answer already stated, it may be worth noting the following. The reason this happens is because it is possible for a class to have a method with the same signature as an interface method without implementing that method. The following code illustrates that:
I just upgraded a solution from MVC3 to MVC5, and started receiving the same exception from my Unit test project.
Checked all the references looking for old files, eventualy discovered I needed to do some bindingRedirects for Mvc, in my unit test project.
In my case, I was attempting to use
TypeBuilder
to create a type.TypeBuilder.CreateType
threw this exception. I eventually realized that I needed to addMethodAttributes.Virtual
to the attributes when callingTypeBuilder.DefineMethod
for a method that helps implements an interface. This is because without this flag, the method does not implement the interface, but rather a new method with the same signature instead (even without specifyingMethodAttributes.NewSlot
).I also ran into this problem while running my unittests. The application ran fine and with no errors. The cause of the problem in my case was that I had turned off the building of the test projects. Reenabling the building of my testprojects solved the issues.
I encountered this error in a context where I was using Autofac and a lot of dynamic assembly loading.
While performing an Autofac resolution operation, the runtime would fail to load one of the assemblies. The error message complained that
Method 'MyMethod' in type 'MyType' from assembly 'ImplementationAssembly' does not have an implementation
. The symptoms occurred when running on a Windows Server 2012 R2 VM, but did not occur on Windows 10 or Windows Server 2016 VMs.ImplementationAssembly
referencedSystem.Collections.Immutable
1.1.37, and contained implementations of aIMyInterface<T1,T2>
interface, which was defined in a separateDefinitionAssembly
.DefinitionAssembly
referencedSystem.Collections.Immutable
1.1.36.The methods from
IMyInterface<T1,T2>
which were "not implemented" had parameters of typeIImmutableDictionary<TKey, TRow>
, which is defined inSystem.Collections.Immutable
.The actual copy of
System.Collections.Immutable
found in the program directory was version 1.1.37. On my Windows Server 2012 R2 VM, the GAC contained a copy ofSystem.Collections.Immutable
1.1.36. On Windows 10 and Windows Server 2016, the GAC contained a copy ofSystem.Collections.Immutable
1.1.37. The loading error only occurred when the GAC contained the older version of the DLL.So, the root cause of the assembly load failure was the mismatching references to
System.Collections.Immutable
. The interface definition and implementation had identical-looking method signatures, but actually depended on different versions ofSystem.Collections.Immutable
, which meant that the runtime did not consider the implementation class to match the interface definition.Adding the following binding redirect to my application config file fixed the issue:
I got this with a "diamond" shaped project dependency:
I recompiled project A but not Project B, which allowed Project B to "inject" the old version of the Project D dll