Question

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?

Was it helpful?

Solution

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).

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top