基本类型不符合 CLS,此警告的原因是什么?
我在我的一堂课上收到了科目的警告。实际上类非常简单,只是我的通用基类型的继承者。此外,我在整个解决方案中还有来自该泛型类的一些其他继承者,并且没有此类警告。
这可能是什么原因? 编译器没有给出任何关于基类型不符合 CLS 的线索
I have got warning from subject on one of my classes. Actually class is very simple, just an inheritor of my generic base type. Also I have some other inheritors from that generic class across the solution, and there are no such warnings.
What could be the reason(s) of this?
Compiler does not give any clues of why base type is not CLS-compliant
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能在该特定项目的某处有
[assemble:CLSCompliant(true)]
。这会触发编译器检查所有类型是否符合 CLS。您可以使用[CLSCompliant(false)]
为类型或方法或其他内容重写此设置。You probably have
[assembly:CLSCompliant(true)]
somewhere in that specific project. This triggers the compiler to check all types to be CLS compliant. You can override this for a type or method or something with[CLSCompliant(false)]
.我猜您有一个标记为 CLSCompliant 的派生类型,但基础类型却没有。
编写符合 CLS 的代码
典型的示例是使用 UInt32,它不是公共语言规范 (CLS) 的一部分 - 因此您需要使用 Int64 来符合 CLS 或删除该属性(声明自己不符合 cls)。
需要更多代码来识别有问题的代码行。有关您遇到的错误的详细信息。
I guess you have a derived type marked as CLSCompliant but the base isn't.
Writing CLS Compliant Code
The canonical example is using a UInt32 which is not part of the Common Language Specification (CLS) - hence you need to use Int64 to be CLS compliant or remove the attribute (declare yourself non-cls compliant).
Need more code to identify the offending line of code. More info on the error you're getting.
我们正在使用 MsBuildTasks,我们注意到的一件事是在
Common.targets
文件中,CLSCompliant
设置为 true。这是在每个AssemblyInfo
文件中设置该值。We are using MsBuildTasks and one thing we notices is that in the
Common.targets
file,CLSCompliant
was set to true. This was setting that value in each of theAssemblyInfo
files.将
false
放入基础项目和引用它的项目的.csproj
文件中。put
<AssemblyClsCompliant>false</AssemblyClsCompliant>
in your.csproj
file of your base project and the project who refer to it.