Error "The type or namespace xxxx does not exist" when compiling Moles in Visual Studio 2012
Asked Answered
C

3

11

I am attempting to compile an existing project (targets .NET4) developed in Visual Studio 2010 and now testing migration to VS2012.

When I compile my existing project with moles, I get the following error a lot.

The type or namespace name 'Claim' does not exist in the namespace 'System.Security.Claims' (are you missing an assembly reference?) [C:\ProjectPath\Project.Tests.Unit\obj\Debug\Moles\m\m.g.csproj] C:\ProjectPath\Project.Tests.Unit\m.g.cs

There is a huge list of various types that show this message.

Any thoughts?

Connaught answered 25/7, 2012 at 10:16 Comment(4)
checked the namespace 'System.Security.Claims' and it is .NET 4.5Connaught
This article adds further information - richonsoftware.com/post/2012/04/20/…Connaught
There is a announcement @ research.microsoft.com/en-us/projects/pex. "The Pex and Moles team will release an update of Pex for Visual Studio 11 when the final release becomes available. Moles will not developed further so we recommend to migrate to Fakes."Poree
The only catch being is that you need an Ultimate Subscription. Testing has become exclusive.Quintilla
B
7

We excluded some namespaces and types from the mole/stub generation based on this article:

Troubleshooting in Visual Studio 11 / .NET 4.5

and it's compiling now (a few test still fails but it's compiling).

Bloodshot answered 5/9, 2012 at 9:11 Comment(1)
See my solution on a similar Pex/Moles issue here: https://mcmap.net/q/1158335/-using-moles-for-tdd-with-httpwebrequestVerdaverdant
H
1

We had difficulty when we upgraded from VS 2010 to VS 2010 SP1. The service pack contains different CLR methods, which the most recent version of Moles doesn't understand.

Heliozoan answered 19/9, 2012 at 10:27 Comment(0)
T
0

I recommend updating your Moles tests to use Fakes and Stubs (the release version of Moles). Fakes and Stubs are included in .NET 4.5 and C# 5, and supported by Visual Studio 2012. Converting to Fakes isn't difficult, as it is basically the same thing as Moles.

I was going to point you to the same article @Peter posted. (Good call, Peter!) The described workaround should clear up your issues.

I believe the issue is that Moles was designed for the 3.0-4.0 .NET frameworks. The 4.5 .NET Framework integrates some of the features new to this version, such as the new asynchronous support. Moles is not tooled to handle this new asynchronous paradigm, and will incorrectly instrument the code. To prevent such issues, compilers typically contain a supported version switch, and simply will not compile code of future versions. This seems to be the case, here. I don't recall, but check the Moles output window; it may be reporting these namespaces are not compiling to a moled assembly.

Regarding the upgrade...

Visual Studio 2012 Update 2 adds Fakes support to the Premium SKU.

I recommend the upgrade, because:

  • Moles Framework has never been officially supported
  • Moles is not a complete product
  • Moles will not receive future updates (such as the one causing this issue)

If you're an employee of a software house, development shop, or IT department, you should be able to easily justify the expense of a VS2012 Premium MSDN subscription SKU to your job manager. If you are paying for yourself and not billing for contract work on a regular basis, or buying the license instead of an MSDN subscription, you'll probably find this a pricy option.

Tourane answered 31/7, 2012 at 17:32 Comment(4)
That's your recommendation? Spend $14,000 to use Fakes? I can't find any place to buy Visual Studio Ultimate 2012 except from MSDN with a $14,000 subscription.Ambulator
OH NO! Thank you for saying something! I certainly would not simply recommend an upgrade, and leave it at that. =( I typically post responses during my commute. I must have accidentally hit the submit button, while exiting the train or something. My bad! Apologies to everyone who now think I am an incredible jerk.Tourane
Note the uservoice: visualstudio.uservoice.com/forums/121579-visual-studio/…Quenchless
I don't think Martijn said it vociferously enough: GO TO HIS LINK AND GIVE AS MANY VOTES AS YOU CAN TO THIS. Totally ludicrous to require ALL members of a team to get the Ultimate version of VS just to use what once was free (via Moles).Endomorphism

© 2022 - 2024 — McMap. All rights reserved.