17

When I run StyleCop, I got this error message saying that I need to Mark the dll with CLSCompliant(true).

What is this? How can I set the Mark the dll with CLSCompliant(true)?

Error   4   CA1014 : Microsoft.Design : 
Mark 'SOMETHING.dll' with CLSCompliant(true) because it exposes externally 
                     visible types. ModelsimCommunicator
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

25

To mark the DLL as CLS compliant do the following in the root namespace.

[assembly: CLSCompliant(true)]

Note: This error is coming from FxCop not StyleCop. FxCop errors are prefixed with CA while StyleCop uses the SA prefix

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 2
    Are you sure it's *in* the root namespace, because Microsoft says have it *before* the namespace. (http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(MARKASSEMBLIESWITHCLSCOMPLIANT)%3bk(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22)&rd=true) – Ian Boyd Aug 29 '11 at 12:07
  • 5
    try adding this to AssemblyInfo.cs – hnafar Jun 30 '15 at 17:41
  • The CA rules are also part of the Code Analysis run when you enable CA for a project. – Patrick Peters Oct 10 '16 at 09:38
  • Credit to @JaredPar and hnafar for the correct answer. For anyone who might encounter this in a WPF application using .NET 6, I just added [assembly: CLSCompliant(true)] to the AssemblyInfo.cs file that was already part of the project template. – Tangere Apps Nov 17 '22 at 13:21
  • I would like to know more about why this occurs. I have a solution of around 70 projects and I get this warning on two of them. The same two projects also raise warning CA2210 "Sign 'my.dll' with a strong name key" which may or may not be coincidental. Obviously I can suppress these warnings, but it would be useful to work out why just these two projects are raising these warnings. Anyone have a clue? (VS2022) – Dave Jul 19 '23 at 08:26
1

To disable:

[assembly: CLSCompliant(false)]