This is a little spooky.
I'm thinking there must be a setting somewhere that explains why this is happening.
In our solution there are about 50 different projects. For the most part, the libraries start with the namespace OurCompany.
We have OurComany.This.That and OurCompany.Foo.Bar... etc.
There is a namespace/class clash between an external library with the namespace
OurCompany.Foo.Bar
And a class that is qualified like so..
OurCompany.Some.Location.Foo
The error goes like this:
Error 75 The type or namespace name 'MethodName' does not exist in the
namespace 'OurCompany.Foo' (are you missing an assembly reference?)
Even Resharper gives me a "Qualifier is redundant" message when I fully qualify anything under the "OurCompany" namespace.. i.e.
OurCompany.Some.Location.Foo.MethodName();
//OurCompany is redundant
I cannot figure out what on earth is doing this. The solution is pretty huge, so ripping things apart to try and reverse engineer the problem is not a great solution for me.
I should state that if I use...
Some.Location.Foo.MethodName(); //Leaving out OurCompany
...the Resharper message goes away.
I thought I understood what was happening here, but now I'm seeing some weird behavior that's making me question my understanding of C#'s namespace scoping behavior.
Obviously, the basic issue is scoping. Presumably, you're working on something in some namespace under
OurCompany
; let's just say for sake of argument, you're inOurCompany.This.That
. Automatically, any types or namespaces found directly in theOurCompany.This.That
,OurCompany.This
, andOurCompany
namespaces are in scope, no usings required. This is why things broke as soon as an assembly with anOurCompany.Foo
namespace got involved (everything inOurCompany
is in scope by default, including theFoo
namespace, and namespaces [apparently] take priority) and also why you're getting the redundant namespace warnings (theSome
namespace is defined in theOurCompany
namespace, so it's automatically in scope).But trying to repro this behavior, I encountered something strange. I created one file to hold the rest of the relevant world:
And found that the following (which I gather is similar to what you're doing) doesn't work:
...but this did:
I freely admit I don't know what's going on here. But apparently the scoping isn't as simple as "Whatever's in scope is in scope, and namespaces take priority."