Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio generates "Settings1.Designer.vb" when I change a configuration setting

Sometimes (not always), when I edit a setting in the "My Project" page, when I add one or edit a value from there, I get an error : 'Settings is ambiguous between declaration in Modules '<project>.My.MySettingsProperty' and '<project>.My.MySettingsProperty'

Visual Studio creates a duplicate of My Project\Settings.Designer.vb, and registers both of them in the .vbproj file.

When this happens, I need to delete Settings.Designer.vb, remove the "1" in Settings1.Designer.vb, and remove the references to it in the vbproj file.

It also happens when I edit a Telerik ORM model (a designer.vb file copied to designer1.vb), with the added problem that in that case, the designer.vb file is empty afterwards.

Here is another description of the problem, by somebody else (who doesn't have an answer since 2009 except mine) : http://social.msdn.microsoft.com/Forums/en-AU/vbide/thread/29e7b9ff-5cdc-456b-9d2f-bc85145e8eaf

Can you think of a possible source, but more importantly, of a possible fix ?

I'm using Visual Studio 2008 Standard, and this problem did not happen a few months ago.

Thanks

like image 976
thomasb Avatar asked Oct 26 '11 09:10

thomasb


3 Answers

I suffered from this too, with Visual Studio 2008, when messing around too much with the application settings. The fix is described here.

In short, in the project file, there is a LastGenOutput XML element inside the XML element of the .settings file. If Visual Studio decides to add a 1 to the generated .Designer.cs file name, this will be persisted to the LastGenOutput XML element. As long as you don't revert this change in the project file, Visual Studio will continue to use the new .Designer.cs file whatever you try.


Update

A reproduction with Visual Studio 2008, 2010 and 2013 Update 1

  1. Create a new .settings file using the settings designer.
  2. In the designer, press "View Code", such that a companion file will be generated.
  3. Ensure the companion file is in the same directory as the other two files.
  4. Exclude all the three files from project.
  5. Show hidden files for the project.
  6. Unload the project.
  7. Reload the project.
  8. Include the three files. Notice that the designer file is now shown below the companion file.
  9. Change a setting in the designer and save. Notice how a second .Designer.cs file is generated.
like image 130
tm1 Avatar answered Nov 16 '22 23:11

tm1


I had a similar problem using Visual Studio 2013: "ambiguous references" on inserting some new images on the general resources of the project. Suddenly it was not possible to compile after this innocent change.

The error shows a text like “Ambiguous reference between modules…” (and mention exactly the same module twice) and repeats for all the possible resources, images or texts. Also it was not possible to select new images for the controls from the list of resources and some windows couldn't be open.

This happened when unexpectedly the Visual Studio IDE duplicate the Resources.Designer.vb on MyProject folder (creating another file with a "1" added to the name: “Resources1.Designer.vb”).

To correct the error I edited the project file .vbproj by hand, erasing the reference to the second Resources.Designer (Resources1.Designer). I also erased the duplicated file from the MyProject folder.

After doing these two things (edition of the project file and deletion of the duplicated file) the project recovered and behaved normally.

I hope this could save some time to someone else on having the same error. Please make a back-up before deleting something!!! ;-)

like image 40
ADeveloper Avatar answered Nov 16 '22 22:11

ADeveloper


Not sure if this is still an issue, but I just got the same problem and fixed it based on the suggestions here. Delete the duplicate file and manually edit the project file.

However, I found something that may be the root cause: I had 2 duplicate sections in my project file, with same elements for the settings file. So I deleted the duplicate ones. I'll see if the problem goes away now.

like image 1
John Berger Avatar answered Nov 17 '22 00:11

John Berger