Skip to content

GeneratedCodeAttribute does not allow multiple #122718

@badcel

Description

@badcel

Description

With the introduction of soruce generators the GeneratedCodeAttribute got more relevant as SourceGenerator authors can document their source generator version on the generated code.

If there are multiple source generators used which want to set the GeneratedCodeAttribute on a partial class this is not possible because the attribute is configured to not allow multiple occurences on the same class.

This could relate to: #64541

A possible workaround is to place the attribute on a deeper level than the class level e.g. methods. This would require all source generator authors to not use the attribute at all on class level as it could always conflict with other source generators.

Reproduction Steps

//MyClass.Tool1.g.cs
[GeneratedCode("Tool1", "1.0")]
public partial class MyClass
{

}

//MyClass.DifferentTool.g.cs
[GeneratedCode("DifferentTool", "2.0")]
public partial class MyClass
{
    
}

Expected behavior

No compiler error.

Actual behavior

Error CS0579

Regression?

No Regression.

Known Workarounds

Do not use the attribute at class level if writing a source generator.

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.CodeDomquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions