Fakes Broken in Visual Studio 2015

泄露秘密 提交于 2019-12-04 08:42:45

问题


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.


回答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



来源:https://stackoverflow.com/questions/31907379/fakes-broken-in-visual-studio-2015

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!