Answer the question
In order to leave comments, you need to log in
How to implement CLS code incompliance warning elimination: CLSCompliant(false) vs pragma warning disable?
Hello! Do you have any thoughts on how to fix CLS code incompatibility warnings? I understand correctly that applying the CLSCompliant(false) attribute to a piece of code will cause the assembly to be incompatible with other projects where there is a requirement for CLS compatibility. Will the use of the pragma directive save in this case?
public class ApplicationContext : DbContext
{
// #pragma warning disable 3003
// or
// [CLSCompliant(false)]
public virtual DbSet<Item> Items{ get; set; }
// #pragma warning restore 3003
}
Answer the question
In order to leave comments, you need to log in
CLS was invented as a guarantee of bytecode compatibility for assemblies compiled from different languages.
In the example above, the only thing we can be afraid of is that tomorrow a CLS-compatible X.3.# compiler will be released, and the X.3.# bytecode will not work with our Items from C#, since the Items property is not CLS compliant.
If all the assemblies that we will work together are written in the same language - C #, there is no problem.
In practice, if CLSCompliant attributes are not set anywhere in the assembly / type / member hierarchy, the entire assembly is considered non-CLS-compliant and there will be no warnings.
https://docs.microsoft.com/en-us/dotnet/api/system...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question