C#: Problem trying to resolve a class when two namespaces are simmilar.

Posted by rally25rs on Stack Overflow See other posts from Stack Overflow or by rally25rs
Published on 2010-05-26T16:10:34Z Indexed on 2010/05/26 16:11 UTC
Read the original article Hit count: 278

Filed under:
|

I'm running into an issue where I can't make a reference to a class in a different namespace. I have 2 classes:

namespace Foo
{
    public class Class1 { ... }
}

namespace My.App.Foo
{
    public class Class2
    {
        public void SomeMethod()
        {
            var x = new Foo.Class1; // compile error!
        }
    }
}

The compile error is:

The type or namespace name 'Class1' does not exist in the namespace 'My.App.Foo'

In this situation, I can't seem to get Visual Studio to recognize that "Foo.Class1" refers to the first class. If I mouse-over "Foo", it shows that its trying to resolve that to "My.App.Foo.Class1"

If I put the line:

using Foo;

at the top of the .cs file that contains Class2, then it also resolves that to "My.App.Foo".

Is there some trick to referencing the right "Foo" namespace without just renaming the namespaces so they don't conflict? Both of these namespaces are in the same assembly.

© Stack Overflow or respective owner

Related posts about c#

Related posts about namespaces