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

Viewed 28042

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...

7 Answers

Since this was a top search result when I had this error, just want to post my cause and solution.

  • I had two projects within a solution, sharing a 'common' class file which was added as a link.
  • I added a second 'helper' class file as a link, used its code within the first, and got the error.

The problem was I had not added the second 'helper' class as a link in both projects.

So the other project had an updated 'common' class, but no knowledge of the 'helper' class it now used.

Note to self: pay more attention to the project column of the error list :)

Related