Skip to content

GeneratedRegex generated class missing [Serializable] attribute #102892

@Luciden

Description

@Luciden

Description

Our security scans are reporting that the generated class implements ISerializable (via RegEx subclass) but fails to add the [Serializable] attribute.

Reproduction Steps

Implement the GeneratedRegEx attribute like the following:

[GeneratedRegex(@"^\d+(?:,\d+)*$", RegexOptions.IgnoreCase, "en-US")]
public static partial Regex CommaSeperatedNumericList();

Note generated class lacks the [Serializable] attribute.

[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "8.0.9.8001")]
file sealed class CommaSeperatedNumericList_0 : Regex

Expected behavior

The generated class should have the [Serializable] attribute.

Actual behavior

The generated class lacks the [Serializable] attribute.

Regression?

Unknown. First time implementing in .Net 8

Known Workarounds

No response

Configuration

  • net8.0
  • Windows 11 and Windows Server 16
  • x64
  • Unknown
  • Not using Blazor

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions