生成Dictionary Shim时出现MSFakes错误

时间:2018-06-14 22:09:02

标签: c# dictionary generics microsoft-fakes shim

我使用msfakes为mscorlib dll中的类生成一些假货。我的mscorlib.fakes文件看起来像这样

<Fakes Diagnostic="true" xmlns="http://schemas.microsoft.com/fakes/2011/">
    <Assembly Name="mscorlib" Version="4.0.0.0"/>
  <StubGeneration>
    <Clear/>
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
    <Add FullName="System.Collections!"/>
    <Add FullName="System.Collections.Generic.List"/>
    <Add FullName="System.Collections.Specialized.NameObjectCollectionBase"/>
    <Add Namespace="System.IO!"/>
  </ShimGeneration>
</Fakes>

它为List<T>生成假货。我继续添加额外的一行,这样我就可以获得Dictionary<TKey, TValue>生成的假货。我的假货文件变成了

<Fakes Diagnostic="true" xmlns="http://schemas.microsoft.com/fakes/2011/">
    <Assembly Name="mscorlib" Version="4.0.0.0"/>
  <StubGeneration>
    <Clear/>
  </StubGeneration>
  <ShimGeneration>
    <Clear/>
    <Add FullName="System.Collections!"/>
    <Add FullName="System.Collections.Generic.List"/>
    <Add FullName="System.Collections.Generic.Dictionary"/>
    <Add FullName="System.Collections.Specialized.NameObjectCollectionBase"/>
    <Add Namespace="System.IO!"/>
  </ShimGeneration>
</Fakes>

这似乎不起作用,当我看到输出窗口时,我得到一个非常神秘的错误我无法理解它

error CS0311: The type 'System.Collections.Generic.Dictionary<TKey, TValue>.KeyCollection' cannot be used as type parameter 'TShimmed' in the generic type or method 'ShimRuntime.Bind<TShimmed, TShim, TBound>(TShim, TBound)'. There is no implicit reference conversion from 'System.Collections.Generic.Dictionary<TKey, TValue>.KeyCollection' to 'System.Collections.Generic.IReadOnlyCollection<TKey>'.[...\obj\Release\Fakes\m\f.csproj]
error CS0311: The type 'System.Collections.Generic.Dictionary<TKey, TValue>.ValueCollection' cannot be used as type parameter 'TShimmed' in the generic type or method 'ShimRuntime.Bind<TShimmed, TShim, TBound>(TShim, TBound)'. There is no implicit reference conversion from 'System.Collections.Generic.Dictionary<TKey, TValue>.ValueCollection' to 'System.Collections.Generic.IReadOnlyCollection<TValue>'. [...\obj\Release\Fakes\m\f.csproj]

有人可以指出我正确的方向吗?

0 个答案:

没有答案