CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

CS8785 error after updating from 8.0.304 to 8.0.306 SDK

Open bh-sijtnic opened this issue 1 year ago • 21 comments

Describe the bug

After updating the .NET 8 SDK from 8.0.304 to the latest 8.0.306 some or our projects targeting framework net8.0-windows10.0.19041 fail with error. We use Visual Studio 2022 17.10.7.

CSC : error CS8785: Generator 'WinRTAotSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may as a result. Exception was of type 'IndexOutOfRangeException' with message 'Index was outside the bounds of the array.'

and

C:\Development\RepoName\.int\Debug\projectname\net8.0-windows10.0.19041\win-x64\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs(5,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements

We did find that adding this to our Directory.Build.props code base "resolves" the issue, though in the documentation we can read its not recommended to use this property. For now we can keep this as a workarround, but we would like to understand the proper fix.

<WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>

To Reproduce

I have not been able to reproduce this yet outside our own code base. We don't know where this code generator comes from and what it triggers.

Exceptions (if any)

CSC : error CS8785: Generator 'WinRTAotSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may as a result. Exception was of type 'IndexOutOfRangeException' with message 'Index was outside the bounds of the array.'

and

C:\Development\RepoName\.int\Debug\projectname\net8.0-windows10.0.19041\win-x64\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs(5,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements

Further technical details

.NET SDKs installed: 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.512 [C:\Program Files\dotnet\sdk] 3.1.423 [C:\Program Files\dotnet\sdk] 5.0.416 [C:\Program Files\dotnet\sdk] 6.0.310 [C:\Program Files\dotnet\sdk] 6.0.427 [C:\Program Files\dotnet\sdk] 8.0.304 [C:\Program Files\dotnet\sdk] 8.0.306 [C:\Program Files\dotnet\sdk]

Visual Studio 2022 - 17.10.7

Windows 10 / Windows 11 Version 23H2

bh-sijtnic avatar Oct 15 '24 09:10 bh-sijtnic