-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JsonSourceGenerator
can fail with global using
aliases
#110242
Comments
Looks like this thing is missing a runtime/src/libraries/Common/src/Roslyn/GetBestTypeByMetadataName.cs Lines 178 to 185 in a25130b
and this probably also applies there: runtime/src/tools/illink/src/ILLink.RoslynAnalyzer/CompilationExtensions.cs Lines 156 to 162 in a25130b
(I guess |
.NET 6 is out of support now so unless the issue also reproduces on .NET 8 or .NET Framework 4.8, it won't be actioned on. |
Hmm actually I didn't realize it's the source generator from .NET 6 which gets executed during the build: So I guess you're right: I missed the deadline by a few days... 😬 Anyway I compared v6.0.36 to v9.0.0, the diff --git a/src/libraries/Common/src/Roslyn/CSharpSyntaxHelper.cs b/src/libraries/Common/src/Roslyn/CSharpSyntaxHelper.cs
index f7ab0d494a5..4638d138e24 100644
--- a/src/libraries/Common/src/Roslyn/CSharpSyntaxHelper.cs
+++ b/src/libraries/Common/src/Roslyn/CSharpSyntaxHelper.cs
@@ -93,6 +93,11 @@ private static void AddAliases(SyntaxList<UsingDirectiveSyntax> usings, ref Valu
if (global != usingDirective.GlobalKeyword.Kind() is SyntaxKind.GlobalKeyword)
continue;
+ // We only care about aliases from one name to another name. e.g. `using X = A.B.C;` That's because
+ // the caller is only interested in finding a fully-qualified-metadata-name to an attribute.
+ if (usingDirective.Name is null)
+ continue;
+
var aliasName = usingDirective.Alias.Name.Identifier.ValueText;
var symbolName = usingDirective.Name.GetUnqualifiedName().Identifier.ValueText;
aliases.Append((aliasName, symbolName)); So I haven't really debugged this, but I suppose So this is basically fixed by #96048, thanks @CyrusNajmabadi 🙂 |
Description
Under some particular conditions,
JsonSourceGenerator
can fail with the following warning:Reproduction Steps
Build the following project:
Expected behavior
I do realize that net6.0 + C# 13 is not officially supported, but I didn't expect a source generator to fail. I expected this to compile successfully without warnings.
Actual behavior
This compiles successfully but
JsonSourceGenerator
fails.The stack trace in the binlog is:
Regression?
I don't know. I was introducing this
global using
alias.Known Workarounds
System.Object
instead ofobject
in the aliasnet6.0
I suspect the generator doesn't handle keywords in
global using
aliases.Configuration
Tested on Windows 11 x64 and Linux x64 (Ubuntu WSL) with the .NET 9 SDK:
.NET SDK:
Version: 9.0.100
Commit: 59db016f11
Workload version: 9.0.100-manifests.c6f19616
MSBuild version: 17.12.7+5b8665660
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100\
Other information
I stumbled upon this by writing the following code in a multi-targeted project:
Using
System.Object
fixed the issue.The text was updated successfully, but these errors were encountered: