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.
I got this in a WCF service due to having an x86 build type selected, causing the bins to live under bin\x86 instead of bin. Selecting Any CPU caused the recompiled DLLs to go to the correct locations (I wont go into detail as to how this happened in the first place).
I got this error because I had a class in an assembly 'C' which was on version 4.5 of the framework, implementing an interface in assembly 'A' which was on version 4.5.1 of the framework and serving as the base class to assembly 'B' which was also on version 4.5.1 of the framework. The system threw the exception while trying to load assembly 'B'. Additionally, I had installed some nuget packages targeting .net 4.5.1 on all three assemblies. For some reason, even though the nuget references were not showing in assembly 'B', it was building successfully.
It turned out that the real issue was that the assemblies were referencing different versions of a nuget package that contained the interface and the interface signature had changed between versions.
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
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 received this error in the following scenario.
var target = Assembly.GetAssembly(typeof(FertPin.Classes.Contact));
The fix for me was upgrading the System.Web.Mvc reference in Assembly B to 4.0.0.0. Seems obvious now!
Thanks to the original poster!