Solved

Namespace problem in my usercontrol

Posted on 2004-09-29
7
744 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now