Shims are not generated for .NET methods

前端 未结 2 1677
孤独总比滥情好
孤独总比滥情好 2021-02-13 09:29

When I began using Microsoft Fakes, I was excited to start shimming some .NET methods. I was lead to believe that I would be able to shim ANY .NET method, static or not: http://

相关标签:
2条回答
  • 2021-02-13 09:50

    I also had the same problem.

    My System.fakes and mscorlib.fakes looked like this :

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="mscorlib" Version="4.0.0.0"/>
      <ShimGeneration>
        <Add Namespace="System.ComponentModel.BackgroundWorker"/>
      </ShimGeneration>
    </Fakes>
    

    and

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="System" Version="4.0.0.0"/>
      <ShimGeneration>
        <Add Namespace="System.ComponentModel.BackgroundWorker"/>
      </ShimGeneration>
    </Fakes>
    

    Solution

    System.fakes

     <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
       <Assembly Name="System" Version="4.0.0.0"/>
       <ShimGeneration>
         <Add FullName="System.ComponentModel.BackgroundWorker!"/>
       </ShimGeneration>
     </Fakes>
    

    mscorlib.fakes

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="mscorlib" Version="4.0.0.0"/>
      <ShimGeneration>
        <Add FullName="System.ComponentModel.BackgroundWorker!"/>
      </ShimGeneration>
    </Fakes>
    

    and after saving the files I Rebuild the solution. And now I have ShimBackgroundWorker.

    0 讨论(0)
  • 2021-02-13 09:54

    Got it working with help from this blog post and here.

    The solution was to add the classes I wanted to shim explicitly in the System.fakes file. This is what mine looks like now:

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
      <Assembly Name="System" Version="4.0.0.0"/>
      <ShimGeneration>
        <Clear/>
        <Add FullName="System.Net.Sockets.TcpClient"/>
        <Remove Obsolete="1"/>
      </ShimGeneration>
    </Fakes>
    

    The Remove Obsolete="1" is to stop errors from being thrown by the Shim generation code when it attempts to shim [Obsolete] code.

    0 讨论(0)
提交回复
热议问题