0

我将一些旧的(不是我自己的)代码引入了我想要修改的新解决方案。我是 C# 新手,所以如果我的术语不正确或遗漏了任何明显的内容,我深表歉意。

我有一个主窗体 MainForm.cs 和继承 PropertyGrid 的自定义组件 CustomComponent.cs。CustomComponent 在 MainForm 中。

我收到一个错误:

The type name 'MainNameSpace' does not exist in the type 'MainNameSpace.MainNameSpace'

在 MainForm.Designer.cs 我有生成的代码:

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
    {
        // stuff
        this.customComponent1 = new MainNameSpace.MainNameSpace();
        // more stuff
    }

如果我手动进入并将其更改为“new MainNameSpace();” 它工作得很好。我不知道为什么命名空间的名称被添加了两次。我尝试检查 .resx 文件是否有任何可疑内容,但没有看到任何内容,并不是说我知道要查找什么。有一个好的起点吗?我已经进入 MainForm、CustomComponent 和所有我能想到的寻找罪魁祸首的东西,但没有找到任何看起来像罪魁祸首的东西。关于我应该在哪里寻找/寻找什么的任何想法?我觉得问题出在 CustomComponent.cs 但我不知道。

自定义组件.cs:

namespace MainNameSpace
{
    public partial class MainNameSpace : PropertyGrid
    {
        public MainNameSpace()
        {
            InitializeComponent();
        }

        // other stuff
    }
}

谢谢!

4

1 回答 1

1

我以前遇到过这个问题,我很确定它与这些行有关:

namespace MainNameSpace
{
    public partial class MainNameSpace : PropertyGrid
    {

命名空间和类不能具有相同的名称,因为它不知道您调用的是哪一个。尝试更改命名空间或类名,它应该可以工作。

希望这可以帮助!

于 2012-09-11T22:03:59.480 回答