The type name {myUserControl} does not exist in the type {myNamespace.myNamespace}

DRapp picture DRapp · Oct 6, 2009 · Viewed 26.6k times · Source

I have a problem (obviously the question :)

I have a project-- MyProject... hence the rest of the project uses a default of any classes as namespace "MyProject"... no problem.

In my project, I created a custom user control that has many other controls on it (label, textboxes, etc). So, that class is ALSO within the default namespace of "MyProject". All compiles no problem. Just to confirm scope visibility, on this user control, I made sure that the DESIGNER code and the Code-Behind (My code) are BOTH within the same "MyProject" namespace (they are), AND they are both respectively PUBLIC PARTIAL CLASS MyUserControl.

Now the issue. I create a simple form (also in namespace "MyProject" by default). From the toolbox, the "MyUserControl" exists so I drag it onto MyNewForm. Drag/Drop is fine.

Save all, compile, fail... The Designer is adding an extra "MyProject" reference thus making it appear that the user control is actually located at MyProject.MyProject.MyUserControl .. instead of MyProject.MyUserControl.

As soon as I manually remove the extra "MyProject.", save and compile, all is fine. However, if I re-edit the form, change something, M$ changes it back to the original "MyProject.MyUserControl" reference.

All that being said, here are the snippets from my project...

namespace MyProject
{
   partial class MyNewForm
   {
      ...
      private void InitializeComponent()
      {
         // THIS is the line that has the extra "MyProject." reference
         // when I manually remove it, all works perfectly
         this.MyUserControl1 = new MyProject.MyUserControl();
      }
   }


   private MyUserControl MyUserControl1;

}

Then, in the MyUserControl definition I have...

namespace MyProject
{
   public partial class MyUserControl : UserControl
   ...
}

and from the MyUserControl via the Designer...

namespace MyProject
{
   public partial class MyUserControl : UserControl
   ...

}

Thanks for the help...

Answer

manji picture manji · Oct 6, 2009

What the designer is doing is ok.

--> You have somehere in your project a namespace called MyProject.MyProject.

(Try finding it in "Class View")