NeuroAgent

Why Does Visual Studio Duplicate Resource Paths?

Learn about the causes of Properties folder duplication in Visual Studio resource paths and effective methods to fix this issue.

Why does adding a resource to a project in Visual Studio cause a path bug?

When adding an icon not in the Properties folder, Visual Studio searches for the file in the Properties folder and gives an error:

File ‘Z:\Programming\CSharpLearning\ProcessMonitorTray\ProcessMonitorTray\Properties\ProcessMonitorTray1.ico’ not found.

If I add a file from the Properties folder through the resource dialog, the following entry appears in the resource file (Resources.resx):

XML code from Resources.resx

Properties\zapret.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

And an error occurs:

File ‘Z:\Programming\CSharpLearning\ProcessMonitorTray\ProcessMonitorTray\Properties\Properties\ProcessMonitorTray1.ico’ not found.

As you can see, when adding a file from the Properties folder, Visual Studio adds "Properties" twice to the path. Why does this happen and how can it be fixed?

NeuroAgent

Visual Studio automatically adds the "Properties" prefix to resource paths, even when the file is already in that folder, due to built-in resource file handling logic. This behavior occurs because the .NET resource system expects all resource files to be in the standard Properties folder and automatically adds this path to all added resources, leading to duplication.

Table of Contents

Main Reason for the Problem

The problem with the duplicated "Properties" path occurs due to Visual Studio’s internal logic when working with resource files (.resx). When you add a resource through the “Add Resource” dialog, the system automatically applies standard behavior for local resources.

As explained in the Microsoft official documentation, Visual Studio uses a specific pattern for processing resource paths. When a file is in the Properties folder, the system tries to “protect” it by adding a prefix, which leads to duplication.

Important: This behavior is not a critical failure but rather a feature of the .NET resource system that was implemented for compatibility with previous versions.

Methods to Fix the Problem

Method 1: Manual Editing of Resources.resx

The most direct way to fix the problem is to manually edit the Resources.resx file:

  1. Open the Resources.resx file in a text editor (not in Visual Studio)
  2. Find the entry with the problematic path
  3. Remove the duplicated "Properties" from the path
  4. Save the file
xml
<!-- Before fix -->
<data name="zapret" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>Properties\zapret.png;System.Drawing.Bitmap, System.Drawing</value>
</data>

<!-- After fix -->
<data name="zapret" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>zapret.png;System.Drawing.Bitmap, System.Drawing</value>
</data>

Method 2: Clearing Custom Tool

As suggested on Stack Overflow, you can try clearing the “Custom Tool” property:

  1. In Solution Explorer, find the problematic resource file
  2. Right-click and select “Properties”
  3. In the “Custom Tool” field, delete the current value
  4. Save changes and reload the solution

Method 3: Changing Access Modifier

Another effective method is to change the “Access Modifier” property:

  1. Open Resources.resx in the Visual Studio editor
  2. In the resource properties window, change “Access Modifier” from “No code generation” to “Public”
  3. Delete the old Designer.cs file and regenerate it

This method is detailed in the Stack Overflow answer.


Preventive Measures

Using the Correct Way to Add Resources

To avoid the problem in the future, use the following recommendations:

  1. Add resources correctly:

    • For files in the Properties folder, add them through “Add Existing Item”
    • Don’t use the “Add Resource” dialog for files already in Properties
  2. Check paths:

    • After adding a resource, check the entry in Resources.resx
    • Ensure the path doesn’t contain duplicate "Properties" entries
  3. Use “View Designer”:

    • As noted by users on Reddit, using “View Designer” (right-click on Resources.resx) often works more reliably

Project Configuration

Configure your project to minimize such issues:

  1. Regularly update Visual Studio:

    • Many similar errors have been fixed in recent versions
    • Check for updates through “Help” → “Check for Updates”
  2. Use source control:

    • As advised on Stack Overflow, use a version control system to track changes to .resx files

Manual Resource File Editing

If automatic methods don’t help, you can manually edit the project file (.csproj):

  1. Open the .csproj file in a text editor
  2. Find entries related to the Resources.resx file
  3. Ensure paths are correct
  4. Remove duplicate entries

Example of a correct entry:

xml
<ProjectItem ReplaceParameters="true" TargetFileName="Resources.resx">Resources.resx</ProjectItem>

As shown in the Microsoft documentation.


Additional Solutions

Using GlobalResourceProxyGenerator

In some cases, changing the “Custom Tool” from “PublicResXFileCodeGenerator” to “GlobalResourceProxyGenerator” helps:

  1. Open the properties of Resources.resx
  2. Change the “Custom Tool” property
  3. Save changes and reload the solution

This method is mentioned in the Stack Overflow answer.

Reloading Solution and Regenerating Files

Sometimes simply reloading the solution fixes the problem:

  1. Close the solution in Visual Studio
  2. Delete the .resx files and associated Designer.cs files
  3. Reopen the solution
  4. Visual Studio will automatically regenerate the necessary files

As described in the Stack Overflow discussion.


Conclusion

The problem with the duplicated "Properties" path in Visual Studio is a known feature of the .NET resource system, not a critical failure. Key takeaways:

  1. Cause: Visual Studio automatically adds the "Properties" prefix to all resource paths for compatibility
  2. Solutions: Manual editing of Resources.resx, changing file properties, clearing Custom Tool
  3. Prevention: Correct resource addition methods, regular Visual Studio updates
  4. Alternatives: Using source control, manual file regeneration

It’s recommended to first try manual editing of Resources.resx, as this is the quickest and most reliable method. If the problem occurs regularly, check for Visual Studio updates or consider alternative approaches to resource management in the project.

Sources

  1. Visual Studio duplicating resource .cs file - Stack Overflow
  2. Troubleshoot Resource Editor errors - Microsoft Learn
  3. Visual Studio resx editor creating duplicate designer file - Stack Overflow
  4. How to Add Resources.resx and Resources.Designer.cs files programmatically - MSDN Forum
  5. Changing Resource files (resx) namespace and access modifier - Stack Overflow
  6. Resource (resx) file import - Stack Overflow