views:

58

answers:

2

I have an odd situation with a user control in VS 2010. The form designer keeps changing my entry and then telling me it does not exist! It compiles and runs the first time, and then if I change something unrelated, it gives me an error in the designer.cs file (Cannot resolve symbol SomeEntry).

private SomeEntry someEntry;
// ...
this.someEntry = new **MyNameSpace**.SomeEntry();

if I remove the MyNameSpace.

this.someEntry = new SomeEntry();

it works, until I make a change again. If I look at the class when the mouse is over the changed designer file, SomeEntry shows SomeEntry.SomeEntry() instead of MyNameSpace.SomeEntry()

Basically, the definition is something like this:

namespace MyNameSpace
{
    public partial class SomeEntry : FormValidatingUserControl
    {
        public SomeEntry()
        {
            InitializeComponent();
        }
    }
}

So, what do I do?

+1  A: 

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.

Jacob
No, I did not rename it and it is not defined more than once. It is a user control that I drop on the form. The user control is fairly simple, basically no added UI elements, one property and one virtual method. If I add the control using codebehind instead of dropping it on the main form, it works. But if I drop it on the main form, it is giving me the above error.
Investor5555
Now this is even more odd. I created a Test UserControl with nothing. If I drag it from the Toolbox to the form, I get the same error.
Investor5555
A: 

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?

Investor5555