Lydon Ch
Lydon Ch

Reputation: 8815

Unable to Shim DateTime.Now in C# dotnet core 3.1

Warning message from Visual Studio Enterprise 2019:

Warning Cannot generate shim for System.DateTime: type is not supported because of internal limitations.    
...\NUnitTestProject1\Fakes\System.Runtime.fakes    1   

Any way to make this Shim working or is this an internal issue that Microsoft has to fix ?

Steps to reproduce:

  1. Expand Frameworks -> Microsoft.NETCore.App -> Right Click on System.Runtime -> Generate Fake Assembly

  2. System.DateTime is contained in System.Runtime.dll for .NETCore 3.1 https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset?view=netcore-3.1

  3. Edit Fakes\System.Runtime.fakes file with

content:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
  <Assembly Name="System.Runtime" Version="4.2.2.0"/>
    <StubGeneration>
        <Clear />
    </StubGeneration>
    <ShimGeneration>
        <Clear />
        <Add FullName="System.DateTime!" />
    </ShimGeneration>
</Fakes>

PS: Adding shim for System.Text.Json works fine.

PS-2: Shimming DateTimeOffset works fine by adding Fake assembly of System.Runtime and using default System.Runtime.fakes

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
      <Assembly Name="System.Runtime" Version="4.2.2.0"/>        
    </Fakes>

Upvotes: 3

Views: 1372

Answers (0)

Related Questions