Troubleshooting in Visual Studio 2012 / .NET 4.5

If you install the .NET Framework 4.5 on a machine, Moles will encounter issues when trying to compile.

The main issue happens when Moles tries to generate stubs or moles for types that exist only in .NET 4.5. Currently, the only workaround is to use filters in the .moles file to avoid loading those types (and dependent types if needed).

For example, this .moles file will properly filter types for mscorlib.dll. Note that it might filter out more types than needed.

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
<Assembly Name="mscorlib" />
<StubGeneration>
<Types>
<Remove Namespace="System.Security.Claims"/>
<Remove Namespace="System.Security.Principal"/>
<Remove Namespace="System.Security.Cryptography"/>
<Remove Namespace="System.IO"/>
<Remove Namespace="System.Threading"/>
<Remove Namespace="System.Threading.Tasks"/>
<Remove Namespace="System.Diagnostics.Contracts"/>
<Remove Namespace="System.Diagnostics.Tracing"/>
<Remove Namespace="System.Reflection" />
<Remove Namespace="System.Runtime!"/>
<Remove Namespace="System.Runtime.InteropServices"/>
<Remove Namespace="System.Runtime.DesignerServices"/>
<Remove Namespace="System.Runtime.CompilerServices"/>
<Remove Namespace="System.Runtime.ExceptionServices"/>
<Remove Namespace="System.Globalization"/>
<Remove Namespace="System.Collections.ObjectModel" TypeName="ReadOnly"/>
<Remove Namespace="System.Collections.ObjectModel" TypeName="Collection"/>
<Remove Namespace="System.Collections.Generic" />
<Remove Namespace="System.Collections.Concurrent" />
<Remove Namespace="System" TypeName="WeakReference"/>
<Remove Namespace="System" TypeName="Progress"/>
<Remove Namespace="System" TypeName="AggregateException"/>
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Remove Namespace="System.Security.Claims"/>
<Remove Namespace="System.Security.Principal"/>
<Remove Namespace="System.Security.Cryptography"/>
<Remove Namespace="System.Threading"/>
<Remove Namespace="System.Threading.Tasks"/>
<Remove Namespace="System.Diagnostics.Contracts"/>
<Remove Namespace="System.Diagnostics.Tracing"/>
<Remove Namespace="System.Reflection" />
<Remove Namespace="System.Runtime!"/>
<Remove Namespace="System.Runtime.InteropServices"/>
<Remove Namespace="System.Runtime.DesignerServices"/>
<Remove Namespace="System.Runtime.CompilerServices"/>
<Remove Namespace="System.Runtime.ExceptionServices"/>
<Remove Namespace="System.Globalization"/>
<Remove Namespace="System.Collections.ObjectModel" TypeName="ReadOnly"/>
<Remove Namespace="System.Collections.ObjectModel" TypeName="Collection"/>
<Remove Namespace="System.Collections.Generic" />
<Remove Namespace="System.Collections.Concurrent" />
<Remove Namespace="System" TypeName="WeakReference"/>
<Remove Namespace="System" TypeName="Progress"/>
<Remove Namespace="System" TypeName="AggregateException"/>
</Types>
</MoleGeneration> </Moles>