Two output file names resolved to the same output

C#.NetWinforms

C# Problem Overview


Recently I created new Form called WorkersScreen. When I try to run the project I got this error:

> Error 1 Two output file names resolved to the same output path: > "obj\x86\Debug\DryWash.WorkersScreen.resources"

What does it mean and how does one resolve it?

C# Solutions


Solution 1 - C#

This can happen in the event of two .resx files pointing to the same form. Mostly happens when renaming forms (other reasons may apply, I'm not exactly sure)

If your particular form files looks like this:

Form1.cs
Form1.designer.cs
MyFormerFormName.resx
Form1.resx

then that usually implies that you renamed the form but Visual Studio didn't remove the old .resx file. Once you delete the file (in this example MyFormerFormName.resx) manually, the error should be gone upon next build.

Solution 2 - C#

Find Duplicates by Editing Project File

  1. Note the name of the .resx failure.

  2. Unload the project first by right clicking on your project then click Unload Project.

enter image description here

  1. Right click your project again and click edit project.

enter image description here

It will show you some code, look (or Search within the file for the resx in step 1) for the duplicate values which in my case is look like this

<EmbeddedResource Include="frmTerminalSerial.resx">
      <DependentUpon>frmTerminalSerial.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmVisual.resx">
      <DependentUpon>frmVisual.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmVisual.resx">
      <DependentUpon>frmVisual.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\Resources.resx">
      <Generator>VbMyResourcesResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.vb</LastGenOutput>
      <CustomToolNamespace>My.Resources</CustomToolNamespace>
      <SubType>Designer</SubType>
</EmbeddedResource>

Notice this portion, it is a duplicate!

<EmbeddedResource Include="frmVisual.resx">
      <DependentUpon>frmVisual.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmVisual.resx">
      <DependentUpon>frmVisual.vb</DependentUpon>
</EmbeddedResource>

Delete one of them so it will look like this

<EmbeddedResource Include="frmTerminalSerial.resx">
      <DependentUpon>frmTerminalSerial.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="frmVisual.resx">
      <DependentUpon>frmVisual.vb</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="My Project\Resources.resx">
      <Generator>VbMyResourcesResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.vb</LastGenOutput>
      <CustomToolNamespace>My.Resources</CustomToolNamespace>
      <SubType>Designer</SubType>
</EmbeddedResource>

Save it, right click to your project then click reload project. You are done!

Solution 3 - C#

Normally, if you create a migration like this

Add-Migration "UpdateProducts"

Visual Studio will create a migration with a class name like UpdateProducts. If you add a new migration later using the same migration name, it will generate a migration with a class name like UpdateProducts1., automatically adding an incremented digit to the end as a suffix. Every time you generate a new migration, the number goes up by one.

In our case, for some reason, VS got confused, and started generating subsequent migrations with the same class name as existing migration, so that that there were two auto generated migrations with the same name.

Simply changing the class name of the new migration clears the problem.

Solution 4 - C#

i did a little search i had the same problem it's probably beacause your form has two .resx if you try to delete one, the problem will be gone my form:

Form1.Designer.cs
Form1.resx
Log_in.resx
Form1

i deleted Log_in.resx and my program worked again

Solution 5 - C#

I just got this issue using VS 2019 community edition.

I didn't have duplicate .resx files. I didn't have duplicate .cs files. I couldn't find the solution online.

To fix the problem, I cleaned the solution and then restarted VS. Not sure why, but it worked. Hope this helps.

Solution 6 - C#

I had the issue and it was caused because I had a partial class of a custom control.

I had accidentally created a .resx file for the partial

I think I did this by hitting shift F7 on the partial class and producing the empty designer form.

Removing the .resx file on the partial class resolved it for me. I was using version control and it was showing that it was a new file.

Hope this helps

Solution 7 - C#

Make sure you don't have two .resx files. See in your project under YourServiceName.cs. Works for me.

Solution 8 - C#

This just happened to me. I had accidentally "Drag and dropped" a form into another. It ended up making a copy of it called "Copy of ". I deleted it and the problem went away.

Solution 9 - C#

This happened to me when I copied a form to reuse most of the functionality and then renamed the form. I went to the directory referenced, found that there was in fact only one file, copied the file in question, renamed it to reference the name of my new form, and then pasted the new file back in the directory.

I don't think this is a good practice (I'm new to C#) but it did work, instead of having to recreate everything. I also needed to update the form name in a few places throughout the solution, surprising in the original form as well as in the new form.

Copying forms does not seem like a good idea.

Solution 10 - C#

In my case, the issue was caused by an EmbeddedResource tag for a designer.resx file that somehow got added to the .csproj file.

Specifically, the following:

<EmbeddedResource Include="Forms\frmMenu.designer.resx">
      <DependentUpon>frmMenu.designer.cs</DependentUpon>
</EmbeddedResource>

Solution 11 - C#

Search in all project the class reported in error list, like in this question case DryWash.WorkersScreen it could be repeated in another file with different file name but inside same class name.

Solution 12 - C#

I got this problem when I accidentally generated a migration with the same name as a business object. The solution is to delete the migration and then create a new one with a different name.

Solution 13 - C#

In my case I had to to open the .csproj in Note++ and looked for .resx files in EmbeddedResource tags I found some strange .resx with strange language suffix example.aa.resx other files were normal files either with no language suffix or with *.ar suffix, I deleted the creepy embedded resource tag and that fixed the issue for me.

Solution 14 - C#

I had this problem today.

Some how the Form.Designer had an extension of .resx, for my solution it was TestForm.Designer.resx. There was already a TestForm.resx. I cleaned the solution, closed down VS, deleted the TestForm.Designer.resx file, and then restarted VS. I still had the error.

I then closed down VS and opened the .proj file using NotePad++ and found that the TestForm.Designer.resx was still referenced. I deleted the embedded resource.

<EmbeddedResource Include="TestForm.Designer.resx">
    <DependentUpon>TestForm.Designer.vb</DependentUpon>
</EmbeddedResource>

Then I opened VS and built....It work's again!

Solution 15 - C#

This happened to me when I run Add Migration command and gave same name as my project name as migration class. I removed all migration classes and added new one, solution build again.

Solution 16 - C#

*In my option, help delete one .resx for every form where the error raised

Detail INFO

In our project we have 6 *.resx for every form for localization (DE,GB,SK,RU,SRB) and if i delete (from VS) FormName.sr-Latn-CS.resx than the error disappeared. If i try deleted FormName.en-GB.resx it did not help. Error disappeared just for delete sr-Latn-CS.resx (maybe a designer can not solved two - ). I first saw this error when I migrated project from VS 2010 Win 7 to VS2010 Win 10.

Solution 17 - C#

If this problem appeared while you were working with EntityFramework and was trying to Add-Migration, the solution is simple: delete Migrations folder (in the Solution Explorer) and execute Enable-Migrations. Backup migrations if you need.

Solution 18 - C#

For me the issue was copying and pasting a .aspx, and not renaming the code behind class files to match the name for the copied aspx file. Changing the code behind and designer class names worked.

Solution 19 - C#

I had the same issue, what I did was delete my migration files (via the studio), after I updated the database.

Solution 20 - C#

As @WimOmbelets stated in his 2013's answer, copying a Form is a very sure way to reproduce this annoying error, at least in VS 2017, 2019 and 2022.

As Vince De Giorgio said in his 2019's answer, I too didn't have duplicate .resx or .cs files and I didn't have duplicate ...EmbeddedResource Include= .../> tags in .csproj.

Deleting .resx files (icons gone, obvious) for both involved forms, clean the solution and then restart VS is a poor man's way to solve, because every time I add again an icon or another resource, same annoying error. It is still worse: to recover, I had to Git stash all modifications; if I revert manually all changes, to the point that Git does not recognize any changes, the error continues (!!!) even after cleaning, restarting VS and rebuilding.

To fix the problem in VS 2019 and 2022:

Every time that I want to copy a form, I:

  1. Exclude Form to be copied from project (exclude, DO NOT DELETE!)
  2. In Windows Explorer I create a Form's copy and open them (.cs and designer.cs) with Visual Code (whatever)
  3. In Visual Studio I create Add a New Form with a different name - of course
  4. Paste back designer.cs and .cs codes from VS code; change namespace, class name and Ctor
  5. Include again in Project previous Form
  6. Enjoy

Never more had this problem.

Solution 21 - C#

I had the same issue in Visual Studio 2022 with a WinForms application in .NET 6.

In this case, I had added a partial class in it's own .CS file to handle custom setup outside of the Designer-generated InitializeComponent.

The next time that I opened the file, Visual Studio 2022 tried to open this in the WinForm Designer. This added a redundant .resx file to the project.

Delete the newly added .resx to correct the error.

Solution 22 - C#

I thought that I would post on at least one random forum after encountering this error in hopes of easing someone elses problems. I searched many google sites and none had my exact problem. My cause was similar, but different in some ways.

I actually had a partial class spread across multiple files. this class was a form class. This was successful in itself and didn't cause a problem. However, this caused the new class to keep its unique file name while maintaining a split 'class Form' code. It was most likely not kosher practice, but none the less it happened at the time. It seemed like a good alternative to get a lot of cluttered code out of the way. Needless to say, next time I will just use regions or some other alternative.

The error then occured when I tried to take the code from the 2nd file and copy/paste into a new non form file with just a class, as I had intended upon essentially turning it into a library and making the code a little more proper and readable. As I didn't know exactly what had caused the error when it happened and had made a small plethora of changes, it took some time to track. Even after reversing the code, I managed to miss a pair of methods.

The methods for the main form containing the class Form with initializeComponent and form constructor (load). A 2nd copy of these methods appeared to result in the same error. Even after deleting the extra code and extra form and resx files. I even tried deleting the legitimate resx file since it was not actively needed. I was unable to effectively track it, because any errors pointed to the legit versions of these code segments. Ctrl+F and backup copies are your friends.

Hope that helps someone

Solution 23 - C#

I confirm WimOmbelets answer given in the comments. This can apparently happen when you rename a class in VS2012 (I never had this in a prior version).

I can't be sure this is the cause, but one thing I did different from my normal way is I used F2 to rename it as opposed to changing it and then pressing control-.

Solution 24 - C#

I had the same issue when I renamed one of my Form classes using Ctrl + R + R which VS provides to rename things by default.

Then I somewhat got two classes with the same class name on 2 different files (*.cs).

class Bar { ... } // From Bar.cs
class Bar { ... } // This should've been Foo, from Foo.cs

The two Bar indicating the same resource file that one of them shouldn't.

It's a trivial issue but sometimes could be hard to find the cause because looking at cs files just can't say which one is what you should look for.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1613523View Question on Stackoverflow
Solution 1 - C#Wim OmbeletsView Answer on Stackoverflow
Solution 2 - C#Cary BondocView Answer on Stackoverflow
Solution 3 - C#spadelivesView Answer on Stackoverflow
Solution 4 - C#athenaView Answer on Stackoverflow
Solution 5 - C#Vince De GiorgioView Answer on Stackoverflow
Solution 6 - C#Tim F.View Answer on Stackoverflow
Solution 7 - C#Marcus SantosView Answer on Stackoverflow
Solution 8 - C#HoustonDevView Answer on Stackoverflow
Solution 9 - C#Bill NazzaroView Answer on Stackoverflow
Solution 10 - C#mtRoomView Answer on Stackoverflow
Solution 11 - C#ahmadalibalochView Answer on Stackoverflow
Solution 12 - C#KirstenView Answer on Stackoverflow
Solution 13 - C#Ali Ezzat OdehView Answer on Stackoverflow
Solution 14 - C#Eric MoonView Answer on Stackoverflow
Solution 15 - C#Teoman shipahiView Answer on Stackoverflow
Solution 16 - C#MajklView Answer on Stackoverflow
Solution 17 - C#Konstantin K.View Answer on Stackoverflow
Solution 18 - C#KeithView Answer on Stackoverflow
Solution 19 - C#JayKayOf4View Answer on Stackoverflow
Solution 20 - C#Marcelo Scofano DinizView Answer on Stackoverflow
Solution 21 - C#Doug KimzeyView Answer on Stackoverflow
Solution 22 - C#BrandenView Answer on Stackoverflow
Solution 23 - C#Aaron AnodideView Answer on Stackoverflow
Solution 24 - C#Dean SeoView Answer on Stackoverflow