Search code examples
c#winformsconstructorvisual-studio-2017

VS2017 WinForms Designer Creating second Constructor on change


In a fresh project, I create a form called FormMain (or any other form, it doesn't matter). This creates the FormMain.cs and a FormMain.Designer.cs. The program builds and launches just fine at this point.

But when I make any change on the GUI Designer (like changing the Form property or adding a MenuStrip from the toolbox) I see that a FormMain.resx is also created and with it, a FormMain1.Designer.cs.

It is then, I get an error

Error CS0111 Type 'FormMain' already defines a member called '.ctor' with the same parameter types

I realized that this is due to the creation of a second constructor under the partial FormMain class, in the newly generated FormMain1.Designer.cs that conflicts with the one in FormMain.cs.

If I delete the constructor in the FormMain1.Designer.cs, the project builds and runs fine. But if I make further changes on the form, the constructor gets created again in FormMain1.Designer.cs and the error repeats. I need the constructor in FormMain.cs and don't want to delete that.

So basically, I can't make changes on the form without deleting the 2nd constructor every time I make a change on the GUI editor. Is this a bug in Visual Studio 2017 (15.9.14)? If it is, any known fix?


Solution

  • Fixed the issue by removing Extended Strongly Typed Resource Generator from Visual Studio. This stops the FormMain1.Designer.cs from being created everytime the form is edited.