ArturPhilibin
ArturPhilibin

Reputation: 933

vb.net System namespace conflict with sibling namespace

I have a class EventArgs(Of T) in my solution.
This class is located in the namespace Acme.Infrastructure.Interface.
A class with the same name EventArgs exists in the System namespace.

In another project in my solution I have a class Acme.BusinessModules.MyModule.MyClass
When attempting to use the EventArgs class I have to fully qualify the class name or the compiler thinks I am using the System.EventArgs class.

My understanding of namespace resolution was that the compiler would first look for the class in the current namespace, and then its parents. It seems that the compiler checks in System before it checks in sibling namespaces.

Is it correct that System is checked before the sibling? Or is this behaviour caused by other issues (Imports order?)?

Upvotes: 1

Views: 2266

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500525

Look at the namespaces involved:

  • Acme.BusinessModules.MyModule
  • Acme.Infrastructure.Interface

There's no reason why the compiler would look in Acme.Infrastructure.Interface when compiling a class in Acme.BusinessModules.MyModule. Now if the code you were writing were in (say) Acme.Infrastructure.Interface.SomethingElse then that would be a different matter - but here it looks like the compiler is doing absolutely the right thing. The fact that both namespaces start with Acme is neither here nor there.

As you yourself said:

My understanding of namespace resolution was that the compiler would first look for the class in the current namespace, and then its parents.

The ancestor namespaces here are Acme.BusinessModules and Acme - not Acme.Infrastructure.Interface.

I would also strongly advise you not to create class names which conflict with those in System. It's really just asking for trouble.

Upvotes: 1

Related Questions