CodeSpeaker
CodeSpeaker

Reputation: 850

Namespace problem

I'm working on an ASP.NET web application with .NET 3.5 and have run into the following problem:

I'm working with a class under the namespace X.Web.Controls.Core which references the class Utils in the namespace X.X2.components.util.

I get an error that Utils is already defined in the namespace X.Web.Controls.Utils This should not be possible since I can't find anything referencing that namespace from the class I'm working on. Any ideas?

Upvotes: 0

Views: 574

Answers (2)

Per Erik Stendahl
Per Erik Stendahl

Reputation: 883

You're working in X.Web.Controls.Core which is a subnamespace of X.Web.Controls. That means the namespace Utils in X.Web.Controls is implicitly visible.

Solve using an alias as suggested by Blixt.

Upvotes: 1

Blixt
Blixt

Reputation: 50187

I can't really see that there should be a problem unless you have a using statement referencing it somewhere. Do take care that code in a namespace will implicitly "see" classes in the same namespace, even if they're defined elsewhere.

Anyways, you can solve your problem by changing the class name (for the current code file only):

using X2Utils = X.X2.components.util.Utils;

The class will be named X2Utils in your code. Alternatively you can make a shortcut for its namespace:

using X2util = X.X2.components.util;

Now you can refer to the class using X2util.Utils.

Upvotes: 6

Related Questions