Search code examples
winformsvisual-studiovisual-studio-2010dispose

Visual Studio .NET error: Form does not contain Dispose(bool) method


Occasionally Visual Studio (2005, 2008, 2010) will lose its mind, and get confused by a WinForm:

SplashForm.cs:

public partial class SplashForm : Form
{
   ...

SplashForm.Designer.cs:

partial class SplashForm
{
   ...
   protected override void Dispose(bool disposing)
   {
      if (disposing && (components != null))
      {
         components.Dispose();
      }
      base.Dispose(disposing);
   }
   ...

It will complain:

  • protected override void Dispose(bool disposing)
    'Dispose(bool)' has no suitable method to override
  • base.Dispose(disposing);
    'object' does not contain a definition for 'Dispose`

It's complaining about code that it generated.

It's been too long (3 years) since i dealt with Visual Studio, so i've forgotten the trick to get Visual Studio's head out of its own assembly.

What's the trick to get it going again?


Solution

  • I had this issue today and found this question. I managed to fix it and while the post is old (2 years old now) I think it is always good to answer it with the solution I found:

    • My Scenario: I created a form in the wrong directory
    • The result: The namespace was different from the namespaces of the other forms.
    • The cause: In my specific case, this was caused because I changed the <Form>.Designer.cs namespace so that it matched the rest of the forms Namespace. But I didn't change the <Form>.cs namespace and that was my mistake.

    So, if you're having this error, make sure both your namespaces from the <Form>.Designer.cs and <Form>.cs match.