Duplicate items are not supported by the "Resources" parameter - c#

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?

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:
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.
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.

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.

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

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.

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

Related

How to rebuild WinForm with just Designer file

I recently picked up a project of mine from a few months ago that I had stored on Github. However, there are a number of forms that apparently did not get stored in the repo. I'm not sure how that happened, but I'm trying to recover as much as I can.
For example:
- CreditsBox.cs
- CreditsBox.Designer.cs
In this case, the CreditsBox.Designer.cs file exists, but the CreditsBox class file does not. Fortunately, the forms that this happened to didn't have too much login in them, so its trivial to rewrite. However, it would make it 10x easier if I could somehow rebuild the form with just the designer file?
Any help is appreciated!
The designer file is all you need to re-create the UI of your forms.
You could follow these steps
Create a new Project.
Add a form and name its file as CreditBox.cs.
Use your saved designer file to replace the one created by Visual
Studio.
As far as I know, the last step could be done also with Visual Studio open but, in any case, better close VS and reopen it afterward.
Of course you could do the same for all other form designer files with the missing main cs file.
So I found a somewhat easy way to fix this.
Create a backup of the .Designer.cs file and delete the original from the project. Then, create a new form in your project with the original form's name (so dependent methods/calls don't fail). Then go through your original .Designer.cs file and create the objects simply by dragging from the Toolbox onto the form and naming it to match the original file. Once you have all of them added (don't worry about styling), copy the old Designer.cs content back in so it will fix the styling, spacing, and all that. Once you build, the designer will update to the original styling/spacing/etc.

In Visual Studio 2013 when I add an existing form then controls don't appear on designer

I'm working on a windows form application. I start a new project. I delete the Form1 stuff from the new project. I go and add from existing in the solution explorer and choose Form1.cs, Form1.Designer.cs, and Form1.resx from another project. When I look at the designer Form1 just looks blank, like a new one would with none of the controls appearing. The program still compiles fine with all it's controls intact. Did I miss a step somewhere? I've closed and reopened the project etc. This happens every single time repeatedly so I believe I'm missing something but searching here or the rest of the web hasn't provided me a solution. Maybe it's just assumed to be known by everyone already?
I am just learning c# and Visual Studio so hopefully I didn't miss something stupid. I was following direction for how to do this from a book. Some projects are re-used to teach a new idea so they have you start a new project and add in existing items from the original to then work on the new idea.
In VS 2013 I chose "Add existing Item" and just selected the .cs files, don't add *.Designer.cs and *.resx files. Then waited for few minutes and restarted VS2013. Designer.cs and resx files appeared as associated with Forms but they were excluded. I right clicked them and chose "Include In Project". Then it worked fine.
Make sure that you are loading the Form1 that you think you are loading.
By default, Visual Studio 2013 (on Windows 7) will create a folder in Documents (C:\Users*Your user name*\Documents) called "Projects". Whenever you create a new project from within Visual Studio by going to File->New Project, Visual Studio will (by default) create a new folder in the Projects folder with the project name.
I think when you "delete" Form1, you're not actually deleting it, just removing it from the project. When you go to add Form1, you're just selecting it from the same project folder, when you actually wanted to load it from a different project folder.
Try this: In your current project (the one where you deleted Form1 and then added it), in the Solution Explorer, right click on the project, and select "Open Folder in File Explorer".
This will open the project folder on disk. Now, delete Form1.cs from within Visual Studio, and switch back to the project folder. If Form1.cs is still in that project folder, then you just removed it from the project. The actual files still exist on disk. When adding existing items, Visual Studio will typically default to the selected project folder.
I have a very strong suspicion that the Form1 that you are really looking for resides in a different project folder. Without knowing the book or tutorial you are following, I can't give you any hints as to where the Form1 you want is located.

not able to change name after copying a form

I'm trying to copy and past a form within a project using Visual Studio.
I've managed to copy and past the form (right clicking in the Solution explorer > Copy; Right click again paste) I can change the name of the new form in the Solution explorer. But when I select the form [Design] I can't change the name property without changing the name property in the original form. Somehow the two are linked. What am I doing wrong?
I hope this all makes sense.
Exclude all files of that form from project and then include again.
You can perform the include steps after reopen the project.

How to solve a "duplicate items" error in the "Resources" parameter

While working on my project, I got this error:
The item "..." was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter.
(Removed the item's name, doesn't matter)
However, I do not know how to solve this. Where do I find this parameter in Visual C# Express?
I guess the item "..." is a form, then:
Remove the "..." form from recent solution (and save somewhere)
Recompile the project
Save the solution
Restart the solution
Add the "..." form
Recompile
Create a backup of both the .cs and .designer.cs file which is giving the error and then delete that file from the project. Rebuild the solution and then copy back both .cs and .designer.cs files. Finally, rebuild the solution again.
I received this error after I copy and paste Form1 (for example) in my project.I rename Copy in Form2, but Form2 had next line in *.cs "public partial class Form1". As i understand after copying class name didn't change. I resolved this problem by adding a new form and copying there controls from my old form. The Old form was deleted.
A slightly simpler way ..
Select the form and then right-click and select "Exclude from Project".
Clean and Recompile project
Select the "Show all files" icon on Solution toolbar to show the excluded form files.
Select the form and then right-click and select "Include in Project" to add it back.
Recompile project
Save All to ensure that project file is saved.
No need to restart Solution or move the form.
This happen when you change name form it duplicate resources file of form.
You open old copy all items and paste to new resource then delete old res file.
Rebuild Solutions.
To fix the issue I browsed to [obj > Debug] and [obj > release] and deleted any files which referenced the word resources. After this, my project built successfully.

What could cause Visual Studio / C# error MSB3105: Duplicate resources

While working on an existing project I suddenly got the following error when trying to compile the solution:
error MSB3105: The item "[filename]" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter.
Now, as far as I'm aware, I did not make any change to the project that affects the resources. Also I have checked each and every file within the project, but there is no duplicate reference anywhere to this file.
Now I already found some forum entries regarding this error:
1) Open the .csproj file and remove the duplicate reference. [Tried this, but I cannot find any duplicates in it]
2) In a 'partial class' project, move everything to a single class. [ Could try this, but the project has been split up into partial classes since the start, and I do not want to change this just because of the error ]
So what else could cause this ?
Did you try showing all files in the Solution Explorer? You could have a duplicate .rsx file somewhere in there.
I found the answer in .NET forum posting by Roy Green, and Theresa was right after all, though I did not recognize it.
If you have your main form class split up into partial classes, the partial sections end up in the solution explorer as separate items. And if you double click on them they show up in the designer mode as a normal form. But if you (accidentally) drop a control on these forms, Visual Studio creates a new .resx file and a InitializeComponent routine for it. But since this form is actually just part of the Main Form class it leads to the 'duplicate resources' error. And there is no other solution but to remove the InitializeComponent routine and delete the .resx file by hand.
Be sure that under yourForm.cs no duplicate resources are defined (.resx). If you renamed your Form, remove the old resource because the new one during compile will be created with the new name.
I just made the same mistake. Delete the mainform.designer.vb, then I restored it again from the recycle bin, and found this error message when compiling.
I try to search on google and someone suggested to check on .vbproj. Did that and found a duplicate on some line.
I had this as well, in VB. There is the "real form" file frmMain, and then I had created new class files and modified them to be Partial Public Class frmMain. For example, I have an ImportFromExcel.vb Partial Class file (I didn't want to clutter up the frmMain.vb with the rather complicated Excel import code.)
Everything worked fine until I decided I wanted to use an OpenFileDialog in the Sub ImportFromExcel. I dragged the OFD from the toolbox over to the Designer view of the ImportFromExcel file. (I have no idea why this view exists, if you can't do anything with it!) But at any rate... dragging the OFD to the Partial Class Designer created an ImportFromExcel.resx file. The drag/drop operation also created an InitializeComponent sub in ImportFromExcel, which is redundant and shows an error -- easily corrected with a little editing.
Ultimately, I chose to not use the dragged resource, but localized the code in the ImportFromExcel.vb file.
All you really have to do is right-click the ImportFromExcel.resx file, and choose Delete. Everything else seems to "fix itself", and it builds fine now.
In my case, this problem happened because a file had the same name but not the same case in the GIT repository.
For example MyFile.cs and myFile.cs.
If you do a checkout on windows, one of the files is overwritten by the other (no message, no warning). So, it is compiling, and we don't notice anything. But if you try to compile on Linux (with .NET Core) both files are present, and there is this error at compile time.

Categories