Reputation: 9725
I have the following code (which compiles and works fine if I leave the warning in, I haven't tested it using the global:: hack):
namespace NotifierService.Models {}
namespace NotifierService
{
using Models;
}
The 'using Models' statement is underlined saying (in the Error List this is only a warning level issue):
Using directives for namespace 'NotifierService.Models' should be qualified
So I then qualify it as:
using NotifierService.Models;
and get the following Error level issue:
The type name 'Models' does not exist in the type 'NotifierService'
P.S. I know I can 'hack' this to remove the warning / error by using the following but I'm trying to understand what/why it is happening as this effect is app wide affecting multiple namespaces.
using global::NotifierService.Models;
ANSWER: Fildor gave me one solution... There was an issue because in my Windows Service the base class used the same name as the namespace, so by renaming all namespaces the application compiled without issue (once I had fully qualified the using statements.
However I just realised a neater solution (Because I prefer the namespaces to have the same name as the project because it makes future referencing more logical/maintainable):
Leave namespaces unchanged, and where I'm using classes from the NotifierService.Models namespace I simply reference them as follows:
List<Models.TaxiModel>
Which allows me to remove the 'using Models'... Still seems a bit strange and 'hacky' though.
Upvotes: 0
Views: 1506
Reputation: 16158
I don't exactly know why it happens but having Namespaces and a class in it have the same name can cause some issues.
Sadly, I haven't kept the project where it happened to me, so I cannot reiterate the issue I had. I just know it was an issue and it was because of the identical names.
The solution on that project was to rename one of the namespace or class. If I remember correctly we renamed the class.
Upvotes: 2