I have Visual Studio 2015 Enterprise and discovered that I cannot compile almost any of our existing 2013 projects. Further investigation reveals that Visual Studio 2015 isn't able to generate fakes for types that were fine in Visual Studio 2013.
Consider the following steps to reproduce:
- Create a unit test project targeting .NET 4.5
- Right-click on "System" in the references tab and choose "Add Fakes Assembly"
- To eliminate the noise for this example, edit the subsequent "System.fakes" file:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
<Assembly Name="System" Version="4.0.0.0"/>
<StubGeneration>
<Clear/>
</StubGeneration>
<ShimGeneration>
<Clear/>
</ShimGeneration>
</Fakes>
- Then edit the "mscorlib.fakes" file to shim ConcurrentDictionary< TKey, TValue >:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
<Assembly Name="mscorlib" Version="4.0.0.0"/>
<StubGeneration>
<Clear/>
</StubGeneration>
<ShimGeneration>
<Clear/>
<Add FullName="ConcurrentDictionary"/>
</ShimGeneration>
</Fakes>
Compile the project.
This generates the following error messages in mscorlib.4.0.0.0.Fakes.messages file (generated in the FakesAssemblies folder):
warning : compilation failed, retrying without Code Contracts
And the following error messages in the output window:
c:\temp\UnitTestProject1\UnitTestProject1\f.cs(955,13): error CS0311: The type 'System.Collections.Concurrent.ConcurrentDictionary' cannot be used as type parameter 'TShimmed' in the generic type or method 'ShimRuntime.Bind(TShim, TBound)'. There is no implicit reference conversion from 'System.Collections.Concurrent.ConcurrentDictionary' to 'System.Collections.Generic.IReadOnlyCollection>'. [c:\temp\UnitTestProject1\UnitTestProject1\obj\Debug\Fakes\m\f.csproj]
c:\temp\UnitTestProject1\UnitTestProject1\f.cs(979,13): error CS0311: The type 'System.Collections.Concurrent.ConcurrentDictionary' cannot be used as type parameter 'TShimmed' in the generic type or method 'ShimRuntime.Bind(TShim, TBound)'. There is no implicit reference conversion from 'System.Collections.Concurrent.ConcurrentDictionary' to 'System.Collections.Generic.IReadOnlyDictionary'. [c:\temp\UnitTestProject1\UnitTestProject1\obj\Debug\Fakes\m\f.csproj]
GENERATEFAKES : error : project compilation failed with exit code 1
No amount of fiddling with mscorlib.fakes settings appears to help. For example various permutations of the TypeName, FullName and Namespace attributes yield the same "compilation failed with exit code 1".
Disabling code contracts just breaks it more:
Warning The element 'Fakes' in namespace 'http://schemas.microsoft.com/fakes/2011/' has invalid child element 'StubGeneration' in namespace 'http://schemas.microsoft.com/fakes/2011/'. UnitTestProject1 c:\temp\UnitTestProject1\UnitTestProject1\Fakes\mscorlib.fakes 4
Any help understanding how to fix/work around this problem would be very much appreciated.