4

By marking the assembly for CLS compliance with [<assembly: CLSCompliant(true)>] I would expect the compiler to issue a warning if the assembly is not compliant. However, I can compile the following

type public Test() =
    member x.intA = 0;
    member x.INTA = 2;
    member x.MyMethod() = 8;
    member x.MYMETHOD() = 10;

without any warning what so ever. Target framework is 4.6 using F# 4.0. Am I missing something, or is it a bug in the compiler? Is there any other way to verify that an assembly generated from F# is compliant?

hvidgaard
  • 495
  • 2
  • 13
  • 2
    public fields and methods in a CLS compliant assembly cannot differ only by casing. /edit: it was an answer to a comment asking why I expected it to issue a warning. The comment has since then been deleted. – hvidgaard Sep 15 '15 at 08:27
  • 1
    Indeed, I just left it there in case someone else was wondering the same. I didn't want to add it to the question, because it's obvious to anyone who work with CLS compliance. In other words, it would be noise to the people actually capable of answering. – hvidgaard Sep 15 '15 at 08:46

2 Answers2

2

From this MSDN page you can see that the attribute is meant to mark the class as compliant and not to ensure compliance. Ensuring compliance is something that the compiler may or may not implement.

Checking the repositories for both Microsoft and FSharp you can see that the CLSCompliant attribute is never used to check for compliance. It is there just to mark the class as compliant, so this behaviour is normal.

Currentlyt I found no tools whatsoever to make this analysis in F#. I opened an issue to see if this feature is relevant enough to get implemented in the compiler. If it is, we all can help get it done. If it ain't, another option is writing an analyzer and releasing it as a VS plugin. Either way I'll keep this answer updated on any news regarding this subject.

William Barbosa
  • 4,936
  • 2
  • 19
  • 37
  • Going through my questions, I decided to mark this as the answer, even though it doesn't explicitly answer it, it provides enough information to determine that F# and automatically checking for CLS compliance isn't currently possible. – hvidgaard Jun 20 '16 at 12:32
0

You will need a tool to check as part of the build. This previous question has answers that discuss options, including FxCop.

Community
  • 1
  • 1
plinth
  • 48,267
  • 11
  • 78
  • 120