by Njål

Visual Studio 2012 Fakes – ShimNotSupportedException when debugging tests



When testing VS2012 Ultimate I tried to use the new Microsoft Fakes framework to mock a simple static method. Running the test went fine, but I kept getting a ShimNotSupportedException when debugging the test. 

After goggling and trying all kinds of stuff I finally managed to debug the test by following these steps:

  1. Deleted the local.testsettings file (both in VS and on disk)

  2. Deleted the <solution>.vsmdi file (both in VS and on disk)
  3. Made sure IntelliTrace had these settings (not sure if this mattered):


  4. Restarted VS2012
  5. Made sure that no .testsettings file were selected here


Debugging of tests now works fine!
(Running/debugging the tests from Resharper still does not work – but I can live with this.)

I tried to add a new .testsettings file (with CodeAnalysis and everything else disabled) – but this makes the ShimNotSupportedException reappear again.

Similar Fakes/ShimNotSupportedException/Debug issues have been reported to MS, so I hope they get this resolved soon.


Another sad fact is that the Fakes framework is only available in the Ultimate edition of Visual Studio 2012 – which retails at over USD 13,000. This makes absolutely no sense at all. ALL developers should use unit testing as part of their tool belt – and isolating tests using a mocking framework plays a key role. Microsoft Moles could be used for free in the previous VS 2010 version – and it worked great. This is very disappointing.

Please vote for this issue here:

by Stian

Moles not compiling

Have you ever experienced that you get a long list of compilation errors after adding Moles Assembly on a reference? The other day I was stucked with several compile errors like:

The command ""C:Program FilesMicrosoft Molesbinmoles.exe" @"D:…objDebugMolesmoles.args"" exited with code –1007
‘System.Net.Moles.SFileWebResponse.Dispose(bool)’: no suitable method found to override [D:…objDebugMolessm.g.csproj]
Cannot call an abstract base member: ‘System.Xml.XmlReader.Close()’ [D:…objDebugMolessxm.g.csproj]
The command ""C:Program FilesMicrosoft Molesbinmoles.exe" @"D:…objDebugMolesmoles.args"" exited with code –1002

I tried to clean, rebuild, restart, re-add, redo and all the other tricks you do when you see a very unreasonable compile error in Visual Studio. The solution seem to be way more unlogical, but it works – so no questions asked at this time.

<Moles xmlns="">
  <Assembly Name="System.Xml" ReflectionOnly="true"/>

moleThe secret seems to be to add the ReflectionOnly attribute and set it to true.

I should mention that while searching for a good explanation for this, I found little information, but it seemed that everybody affected by this was using Visual Studio 2010 SP1. Still, using this version on many other computers, this was the only time I ran into this issue. And I did so with adding Moles assembly for System.Xml 

by thorhalvor

Simple, succinct, pleasant to use

Going full TDD style or not, most developers I know have understood that we need Tests for our code, and when writing tests you need to substitute and isolate parts of code. Frameworks helping out with this, are for example Moles, Typemock, Moq, RhinoMock and NSubstitute. In this blogpost I will focus on the latter. If you interested in a comparison of these you can read Richard Banks blogpost.

NSubstitute’s goal is to be, as the title says, “Simple, succinct, pleasant to use”. And after using it in a project I have to say that it really is! What I find weird though, is that I haven’t heard more noise about it (positive noise: twitter, blogposts etc) until recently, because the guys behind NSubstitute has really done a good job. They don’t even argue about if it is called a mock, stub, test double, fake etc. Instead it is a substitute for something else. Simple!

We’ve attempted to make the most frequently required operations obvious and easy to use, keeping less usual scenarios discoverable and accessible, and all the while maintaining as much natural language as possible.

I woun’t show lots of examples here. If you are looking for that you can go to their Getting-Started pages. There you can see how the easily the mocks are created just by writing var repository = Substitute.For<IUserRepository>(); and how easily you can set up return values by writing repository.Login().Returns(true); They have cleaned up the plumbing code and by adding extensionmethods they have reduced the need for lamdas. Lamdas is good in many cases but they are not that readable in my opinion. And a test should be readable.

NSubstitute has also done a good job in the exceptionhandling when assertions are not met. The errormessage is clear and gives a detailed explanation of which and why an Assert did not return true.

NSubstitute is worth checking out. It’s easy downloadable through their NuGet pacakge. I don’t think I will change the mocking frameworks on projects I am already on but I think I will use it on minor projects until I get more comfortable with the more comprehensive tests.