6

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.

42vogons
  • 683
  • 7
  • 19
  • Quick update on this - we discovered that this error only appears when targeting any .NET framework other than 4.6. We had been avoiding .NET 4.6 due to [this issue](http://blogs.msdn.com/b/dotnet/archive/2015/07/28/ryujit-bug-advisory-in-the-net-framework-4-6.aspx). – 42vogons Aug 24 '15 at 17:00
  • Seems like it currently only works to stub the ConcurrentDictionary. This solved my problems but will most likely not solve yours :/ – Manuel Zelenka Nov 26 '15 at 07:55
  • And there I was too fast typing. I can stub the concurrent dictionary but still can't expect anything from the methods of it... – Manuel Zelenka Nov 26 '15 at 08:06

1 Answers1

-1
  1. If you are doing with Visual Studio 2015 Enterprize.kindly remove Old Xrm dll's and Add new CRM 2016 SDK Xrm Dll's Build the project also change the .Net Framework to latest.

  2. After build the project Generate System Fakes Assembly we will get mscorlib and system.Fakesjust remove this line <Add FullName="ConcurrentDictionary"/>on both files and build the project

Srinivas Hsk
  • 388
  • 3
  • 17