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
referenced System.Collections.Immutable
1.1.37, and contained implementations of a IMyInterface<T1,T2>
interface, which was defined in a separate DefinitionAssembly
. DefinitionAssembly
referenced System.Collections.Immutable
1.1.36.
The methods from IMyInterface<T1,T2>
which were "not implemented" had parameters of type IImmutableDictionary<TKey, TRow>
, which is defined in System.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 of System.Collections.Immutable
1.1.36. On Windows 10 and Windows Server 2016, the GAC contained a copy of System.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 of System.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:
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.37.0" newVersion="1.1.37.0" />
</dependentAssembly>