Skip to content

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

Closed

Description

@dogdie233

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

Activity

  1. added 2 commits that reference this issue on Jan 16, 2025
    2590a6e
    1497494
  2. EdwardCooke commented on Jan 18, 2025

    @EdwardCooke
    Collaborator

    I’ll be sure to merge in that or with the next release. I’m thinking it’ll be this weekend if I have time.

  3. dogdie233 commented on Jan 19, 2025

    @dogdie233
    Author

    I’ll be sure to merge in that or with the next release. I’m thinking it’ll be this weekend if I have time.

    Thank you, i put my context in a namespace as a temporary fix

  4. added a commit that references this issue on Feb 24, 2026
  5. added a commit that references this issue on Apr 9, 2026
    2867ff5
  6. aaubry commented on Apr 10, 2026

    @aaubry
    Owner

    A fix for this issue has been released in version 17.0.0.

  7. aaubry commented on Apr 10, 2026

    @aaubry
    Owner

    A fix for this issue has been released in version 17.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions