Duplicate items are not supported by the “Resource

2020-06-17 04:15发布

问题:

The item obj\Debug\BookStore.MainForm.resources was specified more than once in the Resources parameter. Duplicate items are not supported by the Resources parameter.

How do I fix this?

回答1:

This error happened when you copy and paste a form in the 'Solution Explorer' pane. Then you change name of one forms. Visual studio give the same name for both and then, when you rename form, Visual Studio do some refactoring for you and rename Designer class for both forms (not only for new).

You can fix this two ways:

  1. Close Microsoft Visual Studio, then browse to your project folder from external program (ex. Total Commander). Into the folder where both forms are defined you can see your form's .cs and .Designer.cs file. Open the .cs and .Designer.cs files for your form in a text editor. Find and replace every instance of the original form name with new name. And if you rename already rename some resources, check file for original form also (if they are only original form name but not anything for new form name). Then save all files, start Microsoft Visual Studio and rebuild your project.

  2. You can try chcek and rename declaration for each occurance of original form name in new .cs and .Designer.cs files but try disable refactoring. If you already renamed new form, in .Designer.cs for old form you maybe see this:

    namespace YourProjectNamespace
    {
      partial class NewFormName
      { .. }
    

    You must rename NewFormName to OldFormName and when Visual Studio offer you a refactoring menu (small reg rectangle before last letter of renamed object) do not make anything.



回答2:

This happened to me when I created a partial form class. When I unintentionally viewed it in Design mode it created a localized resx file for the new partial form. I deleted that resx file and that resolved it.



回答3:

you cant add to the resources file 2 items with the same name/key. it has to be unique



回答4:

Check the *.resx files in your project as @Royi Namir described.

In case you have already done that: check your .resx.designer files. Some programs "optimize" the designer files.

The designer files are just plain xml. If they are not in sync with the corresponding xml you'll get an exception as described.



回答5:

I have same problem, and I able to resolve it by these steps:

  • Right-Click to your form name example: MainForm
  • To Review: Select Find All References now you will see the list of form of possible conflicts
  • To Fix: Select Refactor -> Rename -
  • Select Preview reference changes
  • Rename it Differently
  • Un-checked for the Conflict Form/class


标签: c# resources