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 saw this in Visual Studio Pro 2008 when two projects built assemblies with the same name, one a class lib SDF.dll, and one that referenced the lib with assembly name sdf.exe. When I changed the name of the referencing assembly, the exception went away
Here's my take on this error.
Added an
extern
method, but my paste was faulty. TheDllImportAttribute
got put on a commented out line.Ensuring the attribute was actually included in source fixed the issue.
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!
In my case I had previously referenced a
mylib
project in a sibling folder outside of the repo - let's call thatv1.0
.Later I did it properly and used it via a git submodule - lets call that
v2.0
. One projectconsoleApp
however wasn't updated properly. It was still referencing the oldv1.0
project outside of my git project.Confusingly, even though the
*.csproj
was plainly wrong and pointing tov1.0
, the Visual Studio IDE showed the path as thev2.0
project! F12 to inspect the interface and class went to thev2.0
version too.The assembly placed into the bin folder by the compiler was the
v1.0
version, hence the headache.That fact that the IDE was lying to me made it extra hard to realise the error.
Solution: Deleted project references from
ConsoleApp
and readded them.General Tip: Recompile all assemblies from scratch (where possible, can't for nuget packages of course) and check datetime stamps in
bin\debug
folder. Any old dated assemblies are your problem.I had this error too, it was caused by an Any CPU exe referencing Any CPU assemblies that in turn referenced an x86 assembly.
The exception complained about a method on a class in MyApp.Implementations (Any CPU), which derived MyApp.Interfaces (Any CPU), but in fuslogvw.exe I found a hidden 'attempt to load program with an incorrect format' exception from MyApp.CommonTypes (x86) which is used by both.
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.