Skip to content

SYSLIB1045 Quick fix generates badly formed string #104371

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


Create the following class:

public static class Foo
{
    public static readonly Regex IllegalCharactersRegex = new("[" + @"\/:<>|" + "\"]", RegexOptions.Compiled);
}

The quick fix suggest to convert the regex to 'GeneratedRegexAttribute'.

If you do, it generates the following code :

public static partial class Foo
{
    public static readonly Regex IllegalCharactersRegex = MyRegex();

[GeneratedRegex(@"[\/:<>|"]", RegexOptions.Compiled)]
    private static partial Regex MyRegex();
}

But the string is badly formed. It should be @"[/:<>|""]" instead.


Original Comments

Feedback Bot on 6/16/2024, 11:03 PM:

(private comment, text removed)


Original Solutions

(no solutions)

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions