Solved

Namespace problem in my usercontrol

Posted on 2004-09-29
7
746 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 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