5

我有一个 .NET 3.5 C# 项目,其命名空间为SampleNamespace.Tools.Sample.

如果我将一个名为“Samplenamespace.Utils.Example”的程序集添加到我的项目中,我会收到以下警告:

标识符“Samplenamespace”仅在不符合 CLS 的情况下有所不同

注意 中的小写“n” Samplenamespace

目前我什至没有在我的项目中使用参考程序集。只需将其添加为参考就会导致警告。

考虑到我什至没有在我的公共类中公开对程序集的任何引用,为什么编译器会抱怨这个?

任何解决方法?

4

2 回答 2

7

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)

于 2009-06-02T11:08:33.933 回答
3

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.

于 2009-06-02T11:10:13.713 回答