Visual Studio 2010 keeps changing my winforms control

淺唱寂寞╮ 提交于 2019-12-06 11:23:33

It turns out that I should have posted my code EXACTLY as it appeared, as I am sure someone would have figured this out for me sooner.

The issue was that I was trying to simplify for the post, and changed the names of MyNameSpace and SomeEntry to keep it generic.

The project is something the namespace is something (so far, normal) and there was a generated class something from the entity framework.

To reproduce the problem, I created a new project called WinFormTestX. So, the solution is WinFormTestX and the project WinFormTestX. I added a class called WinFormTestX, but did nothing with it.

namespace WinFormTestX
{
    public class WinFormTestX
    {
        public int ID { get; set; }
    }
}

Now, I create a UserControl (UserControl1) and drop a simple button on it. Compile it, and the toolbox adds this control, as expected. Now, I drop it on Form1 and compile it and get an error:

Error 1 The type name 'UserControl1' does not exist in the type 'WinFormTestX.WinFormTestX' D:\Data\Projects\Temp\WinFormTestX\Form1.Designer.cs 31 51 WinFormTestX

As soon as I right click on the class WinFormTestX and Exclude From Project (or delete it), everything works.

So, just having the class in the project of the same name as the namespace, even when it is not used, causes an issue. Obviously, now that I know the cause, there is a simple way around this. But, is this something that is a "bug" that should be submitted to Microsoft?

I've had stuff like this happen when manually moving a class into a new namespace. If you're not careful, your class can become defined multiple times. For example, there may be a residual designer .cs file that still defines the class in its old namespace or some other .cs/.designer.cs mismatch. In other words, your assembly may contain both a SomeEntry.SomeEntry and MyNameSpace.SomeEntry class.

Check the Visual Studio object browser to see if you have SomeEntry defined in multiple namespaces.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!