Solved

Namespace problem in my usercontrol

Posted on 2004-09-29
7
747 Views
Last Modified: 2006-11-17
Hi Experts,

Here is the problem:

namespace MyDirectory.UserControls.MyDirectory.File
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;

public class NewFile : System.Web.UI.UserControl
      {
... code
                }
}

In my Asp .Net UserControl, if in the code, I want to use my other namespace like MyDirectory.MyDirectory.OtherNameSpace, then Visual Studio debugger tells me the namespace is unknown and I can only access to UserControls.MyDirectory.
The 2 namespaces MyDirectory.UserControls.MyDirectory shadows MyDirectory.MyDirectory. Why ?

How to use this namespace without any namespace title modify ?

Thanks in advance for your help. Hope I was clear.

Note that outside the usercontrol namespace, I can use both.
0
Comment
Question by:noulouk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 12184727
Hey noulouk , why do you have such a namespace then :) namespace MyDirectory.UserControls.MyDirectory.File? Dont you want to change it to MyProjectTitle.UserControls.MyDirectory.File?

Best, Nauman.
0
 
LVL 9

Author Comment

by:noulouk
ID: 12184770
No, I don't want to change it. It works inside all my app except for usercontrol.
Or if I change it, this will be:MyProjectTitle.MyDirectory.UserControls.MyDirectory. So same problem.

Sorry for the headhache ;-)
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12185175
Within your user control, add a using statement at the top of the file:

    using MyDirectory.MyDirectory.OtherNameSpace;

Just because they're in the same project/DLL doesn't mean they can automatically reference each other if their namespaces are different.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 9

Author Comment

by:noulouk
ID: 12187971
Thanks Thogek,

I already try this and works well outside the code.
But if I want to use it inside the code the first MyDirectory is UserControls.MyDirectory namespace ?????????? (ie Visual Studio hover menu) .
Is this a Visual Studio bug ?
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12191758
Huh?
It sounds like you're dealing with a namespace clash, but the details are very unclear from the above.  If this is correct, what exactly are the two namespaces of yours that are clashing?
0
 
LVL 15

Accepted Solution

by:
Thogek earned 500 total points
ID: 12191811
One point:
If you have two namespaces that contain classes of the same name, and you reference both namespaces (via using statements) in that class file, then any direct reference to class names shared by both namespaces will necessarily be indeterminant.  (I.e., the compiler has no way to know to which namespace you're referring.)  You can clarify which class you intend to reference by:
    using the full namespace-qualified path of the class (MyDirectory.MyDirectory.MyNameSpace.MyClass)
    define namespace aliases and use them to qualify the class reference (Alias.MyClass - see below)
    don't have classes of the same name in different namespaces

Namespace aliases, in case that doesn't sound familiar, look something like:
    using MyAlias1 = MyDirectory.MyDirectory.MyNameSpace
    using MyAlias2 = MyDirectory.MyDirectory.OtherNameSpace
    MyAlias1.MyClass = ...
More at http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_9_3_1.asp and http://msdn.microsoft.com/library/en-us/csref/html/vclrfUsingDirective.asp
0
 
LVL 9

Author Comment

by:noulouk
ID: 12197842
Perfect, you save my life.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question