I get a warning:
Argument type is not CLS-compliant
What is it, and how can I get rid of it?
I get a warning:
Argument type is not CLS-compliant
What is it, and how can I get rid of it?
In your AssemblyInfo.cs file, you've probably got a line that reads
[assembly:CLSCompliant(true)]
If you do, then the following rules must be met. (Copy-Pasta from http://www.devarticles.com/c/a/C-Sharp/Making-Your-Code-CLS-Compliant/)
Unsigned types should not be part of the public interface of the class. What this means is public fields should not have unsigned types like uint or ulong, public methods should not return unsigned types, parameters passed to public function should not have unsigned types. However unsigned types can be part of private members.
Unsafe types like pointers should not be used with public members. However they can be used with private members.
Class names and member names should not differ only based on their case. For example we cannot have two methods named MyMethod and MYMETHOD.
Only properties and methods may be overloaded, Operators should not be overloaded.
UInt32
and Int64
, and a class could provide a method to convert four consecutive bytes into UInt32
if it also provided one that would return the same value as an Int64
. –
Swaggering This is an old question, but I thought a better explanation was due for future investigators (such as myself).
First off, the links in the other answers provide great detail into the reason this warning is given.
However, to summarize, code written for the Common Language Runtime (such as C#) is CLS-Compliant if it can interface with other languages designed for the CLR. This means that certain datatypes specific to the language that are not common to the entire runtime are not compliant. The quick and easy fix for this in regards to variables and methods is to give them the visibility modifier internal
which specifies that the method, class, property, etc. is not visible outside of the assembly it is being built for. This should only be done on those items which you do not need or want to be used outside of the assembly; for those that you want visible, use datatypes that are CLS-compliant.
Some more info:
And you can get those warnings in a CLS-compliant assembly, that references a non-CLS-compliant assembly (and exposes its non-CLS-compliant members):
© 2022 - 2024 — McMap. All rights reserved.