Visual Studio .NET错误:窗体不包含Dispose(bool)方法 [英] Visual Studio .NET error: Form does not contain Dispose(bool) method

查看:286
本文介绍了Visual Studio .NET错误:窗体不包含Dispose(bool)方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,Visual Studio(2005、2008、2010)会失去理智,并被WinForm弄糊涂:

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);
   }
   ...

它将抱怨:

  • protected override void Dispose(bool disposing)
    'Dispose(bool)'没有合适的方法可以覆盖
  • base.Dispose(disposing);
    对象"不包含处置"的定义
  • 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.

自从我处理Visual Studio以来已经很久了(3年),所以我忘记了将Visual Studio的头脑从自己的程序集中删除的窍门.

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?

推荐答案

我今天遇到了这个问题,并找到了这个问题.我设法解决了这个问题,虽然帖子很旧(现在已经2岁了),但我认为最好用我发现的解决方案来回答它:

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:

  • 我的场景:我在错误的目录中创建了一个表单
  • 结果:名称空间与其他表单的名称空间不同.
  • 原因:在我的特定情况下,这是由于我更改了<Form>.Designer.cs命名空间,使其与其余形式的名称空间匹配而引起的. 但是,我没有更改<Form>.cs命名空间,这是我的错误.
  • 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.

因此,如果遇到此错误,请确保<Form>.Designer.cs<Form>.cs中的名称空间都匹配.

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

这篇关于Visual Studio .NET错误:窗体不包含Dispose(bool)方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆