Link to home
Start Free TrialLog in
Avatar of noulouk
noulouk

asked on

Namespace problem in my usercontrol

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.
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

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.
Avatar of noulouk
noulouk

ASKER

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 ;-)
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.
Avatar of noulouk

ASKER

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 ?
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?
ASKER CERTIFIED SOLUTION
Avatar of Thogek
Thogek
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of noulouk

ASKER

Perfect, you save my life.