Reputation: 48139
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...
Upvotes: 18
Views: 28845
Reputation: 17354
This also happens when you use different pages but with same name. In my case I had created "Grants.xsd" dataset and "Grants.aspx" page. Somehow they got in conflict resulting in this error.
You can easily trouble shoot this by hovering over the culprit keyword (class name) and in Visual Studio 2013, it will tell you exactly where the conflict is.
Upvotes: 0
Reputation: 1641
Just encountered this where I had a MasterPage that had an explicit
<%@ Import Namespace="MyNamespace" %>
in the .master file
Upvotes: 0
Reputation: 199
The Namespace Name and Class Name need to be different. The code generated by adding the WCF automatically references the Namespace but if the Class name is the same as the Namespace name, the generated code looks at the Class and nothing will compile.
Upvotes: 3
Reputation: 47978
What the designer is doing is ok.
--> You have somehere in your project a namespace called MyProject.MyProject
.
(Try finding it in "Class View")
Upvotes: 19
Reputation: 1380
Name of User Control and Form are same. Using different names will solve the issue.
Upvotes: 1
Reputation: 182
PS. to anyone who has same problem but has not found any solution...
Assuming you have created a new WindowsFormApplication;
- Error: The type name 'userControlName' does not exist in the type 'projectName.FormName'
I had research on net for any solution but couldn't come up with any answer...
But if you change the form name any other different from the project name, it'll be resolved.
If you insist on that the form name and project name has to be same depending on your project needs, a custom DLL could be created and use the usercontrol in it.
Then to use as a control, add the DLL file to "ToolBox" using "Choose Items..."
Finally it is going to be ready to use.
PS2. struggling the same problem for hours, this is the solution I found.
Upvotes: 13
Reputation: 4163
Since this was a top search result when I had this error, just want to post my cause and solution.
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 :)
Upvotes: 0