Solved

Namespace problem in my usercontrol

Posted on 2004-09-29
7
743 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 9

Author Comment

by:noulouk
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Perfect, you save my life.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

15 Experts available now in Live!

Get 1:1 Help Now