mike-obrien.net Curriculum Vitae Blog Labs
Tuesday, November 07, 2006

I ran into an issue today where I was coding in a class under a particular namespace but couldn’t access a class in another namespace that only differed by its namespace root. Here is what it looked like:

MyApp.Common.MyClass // Class I want to reference (For a unit test)

TestSuite.MyApp.Common.MyClass // the class I'm coding in (A unit test...)

When I referenced MyApp.Common.MyClass it was actually resolving to TestSuite.MyApp.Common.MyClass. So if you want to reference the former, you need to use the "global::" prefix as follows:

global::MyApp.Common.MyClass

.NET | C#