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

thomasb picture thomasb · Oct 26, 2011 · Viewed 9.6k times · Source

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

Answer

tm1 picture tm1 · Mar 1, 2013

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.