Ciel
Ciel

Reputation: 17762

Why do I need global:: here?

I have run into ...I don't think I would call it a problem as much as I would a quirk. It confuses and confounds me.

I am adding Ninject to my site. It works fine. No questions about troubleshooting Ninject specifically, but I encountered this when setting up my modules...

Here is my SessionModule.cs file.

namespace Lightcast.Web.Mvc.Injection.Modules {
    public class SessionModule : Ninject.Modules.NinjectModule {

        public override void Load() {
        }
    }
}

Also shown in this screenshot.

SessionModule.cs

I get the error

Unknown type 'Modules' of Lightcast.Web.Mvc.Injection.Ninject

Now if I change it to this ...

SessionModule.cs(2)

It works just fine. So obviously there is a namespace collision. What I do not understand is why? I have never encountered this before. It just seems like the absolute oddest thing to me.

Upvotes: 3

Views: 68

Answers (2)

Jon
Jon

Reputation: 437584

There is a class or namespace named Ninject somewhere inside namespace Lightcast.Web.Mvc.Injection.Modules or one of its parent namespaces.

The error occurs because the C# compiler looks up types and namespaces by trying to find them inside the current namespace and working its way towards the global namespace if it cannot.

Upvotes: 4

Florian Greinacher
Florian Greinacher

Reputation: 14784

The reason seems to be that somewhere in your project a namespace or type named Lightcast.Web.Mvc.Injection.Ninject exists that hides the global NInject namespace.

Upvotes: 5

Related Questions