Solved

Namespace problem in my usercontrol

Posted on 2004-09-29
7
748 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

707 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