YamlDotNet icon indicating copy to clipboard operation
YamlDotNet copied to clipboard

[AoT] Compile error if only one StaticContext exist and in global namespace

Open dogdie233 opened this issue 10 months ago • 2 comments
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

  1. Create a C# console project and enable NativeAoT publish. ( Dont trigger Do not use top-level statements)
  2. Add necessary package from nuget. (YamlDotNet and Vecc.YamlDotNet.Analyzers.StaticGenerator)
  3. Delete all template content in Program.cs
  4. 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

dogdie233 avatar Jan 16 '25 20:01 dogdie233