CA1014 Mark 'some.dll' with CLSCompliant(true) error message with StyleCop of VS2010
Asked Answered
C

2

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
Comnenus answered 23/5, 2011 at 21:15 Comment(0)
J
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

Just answered 23/5, 2011 at 21:18 Comment(5)
Are you sure it's in the root namespace, because Microsoft says have it before the namespace. (msdn.microsoft.com/query/…)Wheedle
try adding this to AssemblyInfo.csOsborne
The CA rules are also part of the Code Analysis run when you enable CA for a project.Maritamaritain
Credit to @Just 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.Simson
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)Calisa
K
1

To disable:

[assembly: CLSCompliant(false)]
Kuopio answered 17/8, 2021 at 1:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.