Any reason not to mark a DLL as CLSCompliant?
Asked Answered
F

3

9

I am currently testing out Ndepend, and it gives me a warning that assemblies should be marked as CLSCompliant.

Our project is all C#, so it is not really needed.

What I am wondering is: are there any negative effects of marking a dll as clscompliant or should I just disable the warning?

Note I am not asking what CLSCompliant means that is covered here: What is the 'CLSCompliant' attribute in .NET?

Foregut answered 8/8, 2011 at 12:56 Comment(2)
actually marking your assemblies is a suggestion for code improvement in "effective C#" by Bill Wagner - if you need arguments for your boss. see: amazon.com/Effective-Specific-Ways-Improve-Your/dp/…Estancia
FxCop recommends to mark assemblies as CLS compliant, as well. That said, be aware that you can mark assemblies as CLS compliant as a whole, and then exclude single types or members within those assemblies with a [CLSCompliant(false)] attribute. This can be necessary if you also want to return or accept some types from 3rd party libraries that are not CLS compliant on their own.Agminate
S
8

This is one of those subtle cases... CLS compliance is probably of most importance to library authors, who can't control who the caller is. In your case, you state "our project is all C#", in which case you are right: it isn't needed. It adds restrictions (for example, on unsigned types) which might (or might not) affect representing your data in the most obvious way.

So: if it adds no value to you whatsoever, then frankly: turn that rule off. If you can add it for free (no code changes except the attributes), then maybe OK - but everything is a balance - effort vs result. If there is no gain here, don't invest time.

If you are a library author (merchant or OSS), then you should follow it.

Simplicity answered 8/8, 2011 at 13:11 Comment(0)
M
2

There are several C# features that are not CLS compliant, for example unsigned types. Since several languages are case insensitive, there must be no types and members that differ only by case, e.g. MyObject and myObject, and several other features. Thus, if you don't plan to work with other .NET languages there is no reason to mark your code as CLSCompliant.

Mceachern answered 8/8, 2011 at 13:12 Comment(0)
A
1

The only negative effects would be compiler errors when your code is marked as CLSCompliant, but it is not.

Agricola answered 8/8, 2011 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.