views:

979

answers:

2

I have a .NET 3.5 C# project that has a namespace of "SampleNamespace.Tools.Sample"

If i add an assmebly called "Samplenamespace.Utils.Example" to my project i get the following warning.

"Identifier 'Samplenamespace' differing only in case is not CLS-compliant"

Note the lower case 'n' in Samplenamespace.

I'm not even using the refernece assmebly in my project at the moment. Simply adding it as a reference causes the warning.

Why is the complier complaing about this considering i'm not even exposing any references to the assmebly in my public classes.

Any workaround?

+4  A: 

Not all .NET languages are case sensitive (VB for example) when you have mixed namespaces like this, diffing only in case (to use the wording of the warning) your code may not be accessable to other developers.

That may not be your case, which is why it's a warning (which in my shop we treat as an error)

Ralph Shillington
Thanks Ralph, i'm still not understanding why this should matter since my project is not exposing anything form the referenced assembly to any potential VB clients. I'm effectively abstracting the VB client from the underlying assembly?
Since VB is not case-sensitive, It is not able to differentiate between SampleNamespace.A and Samplenamespace.A and hence it is not able to determine which type to invoke. To prevent such ambiguity the C# Compiler flags this up so that you can only create types and members that can be invoked by everyone without any ambiguity.
Gishu
I think, It is a blind check-and-flag, it is not considering how you are actually using or exposing the types.
Gishu
There is no way it can *know* whether the code is accessed from VB. What if someone on another computer next week is going to write an assembly in VB which calls some functions in yours? Anything in your assembly is available to other assemblies. And those other assemblies may be written in any .NET language.
jalf
A: 

It is simply warning you since not all languages that can consume the types within your solution will be aware of the difference (and may be unable to use the types).

I think that you can avoid this warning by marking your assembly as being non-CLS compliant (in the AssemblyInfo.cs file) (read more here):

[assembly:CLSCompliant(false)]

Not sure I think it's a good idea though...

Update: I think that the reason that the warning is issued though nothing is publicly exposed is that namespaces do not have access modifiers. You could perhaps say that namespaces are always public, so they are exposed to potential clients, even though they may not contain any public types.

Fredrik Mörk
Fredrik, i could make the code none CLS-Compliant but i'd rather not considering the any client code of my app is not exposed to this assembly. It just doesn't seem like a valid situation to break CLS-Compliance.
I got curious as well and did some tests; see my update in the answer.
Fredrik Mörk
That makes since Fredrik. I suppose my only options are to either change the namespace or set CLS compliance to false. Thanks for you help