YamlDotNet
YamlDotNet copied to clipboard
[AoT] Compile error if only one StaticContext exist and in global namespace
trafficstars
Describe the bug
In the project, if there is a unique class with YamlStaticContext attribute, and this class is in the global namespace, while there are other classes with YamlSerializable attribute, the compilation will fail.
To Reproduce
- Create a C# console project and enable NativeAoT publish. ( Dont trigger
Do not use top-level statements) - Add necessary package from nuget. (
YamlDotNetandVecc.YamlDotNet.Analyzers.StaticGenerator) - Delete all template content in
Program.cs - Paste code.
Console.WriteLine("Hello world");
[YamlDotNet.Serialization.YamlSerializable]
public class Model {}
[YamlDotNet.Serialization.YamlStaticContext]
public partial class YamlContext : YamlDotNet.Serialization.StaticContext {}
Build output here
$ dotnet build
Restore complete (2.2s)
BugReproduceProject failed with 1 error(s) (0.4s)
C:\BugReproduceProject\obj\Debug\net9.0\YamlDotNet.Analyzers.StaticGenerator\YamlDotNet.Analyzers.StaticGenerator.TypeFactoryGenerator\YamlDotNetAutoGraph.g.cs(8,10): error CS1001: Identifier expected
Build failed with 1 error(s) in 2.9s