Skip to content

GenerateResource task fails with a resource string key/name containing an equals or back tick character in a resources file (resx) #13061

@ramiabughazaleh

Description

@ramiabughazaleh

Issue Description

Hi.

The GenerateResource task fails with a resource string key/name containing an equals or back tick character in a resources file (resx).

Building the same resources file works when using ResXFileCodeGenerator or PublicResXFileCodeGenerator.

Steps to Reproduce

  1. Create a new C# project (ex. "MSTest Test project").
  2. Add a new resources file (ex. "Resource1.resx").
  3. Add a new resource with the name equals and value =.
  4. Notice the project builds successfully.
  5. Right-click on the resx file and select "Open With..." and select "XML (Text) Editor".
  6. Change the name from equals to =.
  7. Notice the project builds successfully.
  8. Open the csproj file and replace this:
  <ItemGroup>
    <Compile Update="Resource1.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>Resource1.resx</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Resource1.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resource1.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

With this:

  <ItemGroup>
    <EmbeddedResource Update="Resource1.resx" Type="Resx">
      <Generator>MSBuild:Compile</Generator>
      <StronglyTypedLanguage>$(Language)</StronglyTypedLanguage>
    </EmbeddedResource>
  </ItemGroup>
  1. Notice the build fails with the following errors:
1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3557: Error(s) generating strongly typed resources for file "Resource1.resx".
1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3567: Could not generate property on class "=".

Expected Behavior

I expected the build to succeed and a strongly typed class generated for the resources file.

In production, my string resource key is not actually one character, but more like:

'User name' contains invalid characters. The following characters are not allowed: &quot;/[]:|&lt;&gt;+=;,?%@`

And the error is

Could not generate property on class "'User name' contains invalid characters. The following characters are not allowed: "/[]:|<>+=;,?%@`"

So it was not exactly clear why the property on the class was not generated (which characters caused the issue).

If I remove the equals sign (=) and back tick (`) characters, the build succeeds and the strongly typed class is generated successfully.

The name of the property that is created has underscore characters instead of some of the other symbols, so I expected the GenerateResource task to do the same for the equals and back tick characters.

Actual Behavior

The build fails with the following errors:

1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3557: Error(s) generating strongly typed resources for file "Resource1.resx".
1>C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(3442,5): error MSB3567: Could not generate property on class "=".

A strongly typed class is not generated.

Analysis

No response

Versions & Configurations

Windows 11 Version 25H2 (OS Build 26200.7171)
Visual Studio 2026 Version 18.1.1
MSBuild version 18.0.5+e22287bf1 for .NET Framework 18.0.5.56406

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions