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 have yet another esoteric solution to this error message. I upgraded my target framework from .Net 4.0 to 4.6, and my unit test project was giving me the "System.TypeLoadException...does not have an implementation" error when I tried to build. It also gave a second error message about the same supposedly non-implemented method that said "The 'BuildShadowTask' task failed unexpectedly." None of the advice here seemed to help, so I searched for "BuildShadowTask", and found a post on MSDN which led me to use a text editor to delete these lines from the unit test project's csproj file.
After that, both errors went away and the project built.
Another explanation for this type of problem involving managed C++.
If you try to stub an interface defined in an assembly created using managed C++ that has a special signature you will get the exception when the stub is created.
This is true for Rhino Mocks and probably any mocking framework that uses
System.Reflection.Emit
.The interface definition gets the following signature:
Note that the C++ type
long
maps toSystem.Int32
(or simplyint
in C#). It is the somewhat obscuremodopt
that is causing the problem as stated by Ayende Rahien on the Rhino Mocks mailing list .I faced almost same issue. I was scratching my head what is causing this error. I cross checked, all the methods were implemented.
On Googling I got this link among other. Based on @Paul McLink comment, This two steps resolved the issue.
and the error gone.
Restart VS Plugin
Thanks Paul :)
Hope this helps someone who come across this error :)
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 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.
This error can also be caused if an assembly is loaded using Assembly.LoadFrom(String) and is referencing an assembly that was already loaded using Assembly.Load(Byte[]).
For instance you have embedded the main application's referenced assemblies as resources but your app loads plug-ins from a specific folder.
Instead of using LoadFrom you should use Load. The following code will do the job: