Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS8785 error after updating from 8.0.304 to 8.0.306 SDK #44145

Open
bh-sijtnic opened this issue Oct 14, 2024 · 11 comments
Open

CS8785 error after updating from 8.0.304 to 8.0.306 SDK #44145

bh-sijtnic opened this issue Oct 14, 2024 · 11 comments
Assignees
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@bh-sijtnic
Copy link

bh-sijtnic commented Oct 14, 2024

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 11 Version 23H2

@manodasanW
Copy link
Contributor

manodasanW commented Oct 15, 2024

@nico-1987 I saw you were able to workaround the issue. Can you also try the WindowsSdkPackageVersion for the latest Windows SDK projection update with the current known issues fixed to confirm whether it addresses your issue or not. If it doesn't, can you post a snippet of the generated code where the error happens in an issue that you open in the CsWinRT repo. If it does resolve it, this version will be the default in next month's .NET SDK servicing update at which point you can remove the WindowsSdkPackageVersion property.

@bh-sijtnic
Copy link
Author

Thanks for the quick update, i just tested in our .NET 6 product with

    <WindowsSdkPackageVersion>10.0.19041.52</WindowsSdkPackageVersion>

This did not fix the issue, actually the whole WinRT.SourceGenerator folder, and thus Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs does not exist (anymore?) in our obj path (for which we use a custom path)

    <IntermediateFolder>$([MSBuild]::NormalizePath($(RootSourceFolder).int/))</IntermediateFolder>

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

@ekalchev
Copy link

ekalchev commented Oct 21, 2024

I suffer from the same issue after .Net 8 SDK update to 8.0.403

25>        Microsoft (R) Visual C# Compiler version 4.11.0-3.24376.4 (5e3a11e2)
25>        Copyright (C) Microsoft Corporation. All rights reserved.
25>        CSC : error CS8785: Generator 'WinRTAotSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'IndexOutOfRangeException' with message 'Index was outside the bounds of the array.'.
25>        System.IndexOutOfRangeException: Index was outside the bounds of the array.
25>        at Generator.WinRTAotSourceGenerator.GetVtableAttributesToAddOnLookupTable(GeneratorSyntaxContext context, TypeMapper typeMapper, Func`3 isWinRTType, Func`2 isWinRTClass)
25>        at Generator.WinRTAotSourceGenerator.GetVtableAttributesToAddOnLookupTable(GeneratorSyntaxContext context, TypeMapper typeMapper)
25>        at Generator.WinRTAotSourceGenerator.<>c.<Initialize>b__0_17(ValueTuple`2 t, CancellationToken _)
25>        at Microsoft.CodeAnalysis.TransformNode`2.<>c__DisplayClass6_0.<.ctor>b__0(TInput i, CancellationToken token)
25>        at Microsoft.CodeAnalysis.TransformNode`2.UpdateStateTable(Builder builder, NodeStateTable`1 previousTable, CancellationToken cancellationToken)
25>        -----
25>        CompilerServer: server - server processed compilation - WordApp_d0yh1ael_wpftmp (net8.0-windows10.0.17763.0)

I tried all workarounds for this issue but nothing works

@ekalchev
Copy link

The only fix that works for me is:

dotnet-core-uninstall remove 8.0.403 --sdk

@KarlKl
Copy link

KarlKl commented Oct 28, 2024

Have you tried the workaround to disable WinRT AOT optimizer in project file, that was proposed here?

<CsWinRTAotOptimizerEnabled>false</CsWinRTAotOptimizerEnabled>

At least for me it did work.

EDIT: Sorry, I just saw that you posted there that it didn't work for you.

@baronfel
Copy link
Member

@ekalchev please provide a binlog - we think the issue should be fixed but without further details we can't dig into what's going on in your system.

@ekalchev
Copy link

@baronfel is this enough or you need the entire log?

Image

@baronfel
Copy link
Member

Unfortunately It's not enough to double check if you applied the workaround described above and/or see if there's some other context in your working environment that triggers the issue.

If you can create a developer community ticket to securly upload the binlog we can privately investigate if that's alright with you.

@ekalchev
Copy link

@baronfel Here the ticket https://developercommunity.visualstudio.com/t/Building-with-SDK-80403-throws-CSC-err/10779441
I attached two binlog files with and without

<CsWinRTAotOptimizerEnabled>false</CsWinRTAotOptimizerEnabled>

@baronfel
Copy link
Member

@manodasanW can you take a look at the binlogs and offer guidance?

@manodasanW
Copy link
Contributor

I believe we have fixed this issue for our next update. But CsWinRTAotOptimizerEnabled set to false should have workaround this issue at least with the version mentioned here of the Windows SDK projection. I will take a look at the binlogs to see why it didn't help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

5 participants