microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.05k stars 85 forks source link

PInvoke006: An error occurred while reading docs file #953

Closed 0xced closed 11 months ago

0xced commented 1 year ago

Actual behavior

Warning PInvoke006 occurs when using the latest compiler toolset (i.e. Microsoft.Net.Compilers.Toolset 4.6.0).

Expected behavior

No warning is produced.

Repro steps

  1. MyProject.csproj content:

    
    <Project Sdk="Microsoft.NET.Sdk">
    
    <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    </PropertyGroup>
    
    <ItemGroup>
    <PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.6.0" PrivateAssets="all" />
    <PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.2-beta" PrivateAssets="all" />
    </ItemGroup>

2. `NativeMethods.txt` content: (an empty file is enough to trigger the warning)


`dotnet build` produces the following warning:
> CSC : warning PInvoke006: An error occurred while reading docs file: "%USERPROFILE%\\.nuget\packages\microsoft.windows.sdk.win32docs\0.1.41-alpha\ buildTransitive\..\apidocs.msgpack": Failed to deserialize System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=6 .0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.Windows.SDK.Win32Docs.ApiDetails, Microsoft.Windows.SDK.Win32Docs, Version=0.1. 41.51634, Culture=neutral, PublicKeyToken=7c40c7c34b1fcfe1]] value. [C:\MyProject\MyProject.csproj]

### Context

- CsWin32 version: 0.3.2-beta
- Win32Metadata version: not set explicitly
- Target Framework: net6.0
- `LangVersion`: not set explicitly

### Additional info

The warning does not occur when using Microsoft.Net.Compilers.Toolset version 4.5.0.
AArnott commented 1 year ago

I can repro it as you say, when I use dotnet build. Thank you for this report.

AArnott commented 1 year ago

@sharwell do you have any guesses as to what breaking change may have occurred in Roslyn between the 4.5.0 and 4.6.0 versions?

alexrp commented 11 months ago

I've started running into this as well, in a .NET 8 RC 1 project. Oddly, it only appears in VS Code, not with dotnet build... 🤔