What could cause Visual Studio / C# error MSB3105:

2020-04-02 07:28发布

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 ?

6条回答
beautiful°
2楼-- · 2020-04-02 07:53

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.

查看更多
Lonely孤独者°
3楼-- · 2020-04-02 07:57

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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2020-04-02 07:59

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.

查看更多
你好瞎i
5楼-- · 2020-04-02 08:01

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.

查看更多
虎瘦雄心在
6楼-- · 2020-04-02 08:05

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.

查看更多
相关推荐>>
7楼-- · 2020-04-02 08:17

Did you try showing all files in the Solution Explorer? You could have a duplicate .rsx file somewhere in there.

查看更多
登录 后发表回答