Skip to content

Analyzer warning for missing XML doc on source-generated Program class #61783

Open
@mikekistler

Description

@mikekistler

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Beginning with .NET 10 preview1, a source generator adds public partial class Program to a Program.cs file that uses top-level statements. This automates a step that developers previously had to do manually for integration testing of their apps.

But when the project is configured to GenerateDocumentationFile, this results in an odd analyzer warning on the first statement in Program.cs:

Image

But the warning cannot be resolved by adding an XML comment above this first statement (which is actually the fix suggested by Copilot):

Image

The only way I could find to resolve this is by adding public partial class Program {}; at the end of the file with an XML comment on it.

Image

Oh ... there is another way, which is to suppress the analyzer warning for missing XML comment on the public partial class Program; statement:

Image

Expected Behavior

I think statements added by source generators should not cause analyzer warnings. So I think the source generator in this case should add the suppression pragmas as shown above.

Steps To Reproduce

Create a new .NET 10 webapi and then enable GenerateDocumentationFile in the project file.

Exceptions (if any)

No response

.NET Version

10.0.100-preview.4.25229.110

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions