1

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?)?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, was just my misunderstanding of the namespaces system then, time to do some reading. The class with the same name was created by SCSF!
@DaSilva_Ireland: I've never used SCSF, but you should absolutely see if you can disable that class generation (or just delete it if it was a one-time thing). It will just cause you pain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.