0

I have two solutions, one functional, the other experimental. I made some forms and code that I want to import from Experimental to Functional.

I followed directions found here to import the forms.

  1. Add the existing files (cs, designer, and resx) from the Experimental folder
  2. Exclude them from solution
  3. Add them again from the Functional folder
  4. Done (sort of)

What I encountered was that I needed to change the namespace on the FormOne.Designer.cs file to match that of the Functional solution:

namespace WindowsFormsApp1

Changed to:

namespace ProjName

After doing that and saving it worked for FormOne.

But following the exact same procedure (one form at a time) for FormTwo and FormThree fails. When I try to build or rebuild the solution or project I get:

FormTwo.Dispose(bool): no suitable method found to override

I get this same error for both FormTwo and FormThree. I did a copy/paste of the namespace line to ensure I did not make a typo when entering it.

  • Post the minimum amount of code necessary to replicate the error – Caius Jard Apr 27 '20 at 15:43
  • When you were adjustng the namespaces (not needed; you can just import missing ones) did you accidentally remove the declaration that FormTwo inherits from Form? – Caius Jard Apr 27 '20 at 15:51

1 Answers1

0

Forms use the partial class functionality to combine the Form1 in the code file you edit (Form1.cs) with the Form1 in the file the designer edits (Form1.Designer.cs)

The designer code overrides Dispose(), a method that it can override because the Form1 class in Form1.cs inherits from Form, which has an overridable Dispose(). The partial class Form1 in the designer file doesn't inherit anything (it can't inherit Form also because that is already done in Form1.cs; you can't inherit twice)

If you change the namespace of the Form1 class in the Form1.cs class and forget to change the namespace of the class in the Form1.Designer.cs you will cause two classes both called Form1 in your project, in different namespaces. The Form1 in the Designer file, that doesn't inherit from Form, cannot thus have aDispose()` to override:

enter image description here

FWIW you don't NEED to edit the namespaces; your forms from the old namespace can be used in the forms of the new namespace just by adding a "using OldNamespace" at the top of the forms in the new namespace

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • So I figured out that JUST typing in or copy/pasting the new namespace was not enough. Afterwards, I had to actually select the Rename function from the right click menu and run that. Then open the tab up for the form GUI and let it digest the new changes for a few seconds. – GooberGrape Apr 27 '20 at 16:21
  • Yes, it doesn't matter how the namespace comes to be changed (direct edit, find replace, rename function etc) it just has to be consistent between FormX.cs and FormX.Designer.cs, for the reasons i give above. – Caius Jard Apr 27 '20 at 16:29