1

I have an external assembly that I use, and for whatever reason it does not specify CLS Compliance. So, this causes a lot of my code to be marked as non-cls compliant. The problem I'm running into is the following:

public abstract class SomeClass
{
    //Compiler Error CS3011
    [CLSCompliant(false)]
    public abstract object SomeMethod(ExternalNonCompliantType arg);
}

public abstract class SomeClass
{
    //Argument type 'External.ExternalNonCompliantType' is not CLS-compliant
    public abstract object SomeMethod(ExternalNonCompliantType arg);
}

CS3011:

A class member cannot be both abstract and non-compliant with the Common Language Specification (CLS). The CLS specifies that all class members shall be implemented.

I'm really not sure what to do here...

myermian
  • 31,823
  • 24
  • 123
  • 215

1 Answers1

2
  • What is the expected use of the code that you are writing?
  • Can you just make your whole assembly as [CLSComplaint(false)]?

If your assembly is also not-compliant, then you should be ok with this kind of code. You can also try to mark the one class as Non-Compliant. I've always just marked the whole assembly.

If this is just your code, and you aren't distributing it as a library, it shouldn't be an issue and you don't need to worry too much about CLS compliance.

The one exception is if you are writing something internally that you expect to be able to re-use in a wide variety of other CLR languages like F#, vb.net, ironpython, boo, M, scala, etc. Thats probably not the case; most apps are just that - apps.

Andrew
  • 8,322
  • 2
  • 47
  • 70
  • 1
    I'm writing a library I plan to distribute, and I want my library to be CLS Compliant. I will give an upvote because the suggestion of marking the entire class as non-cls compliant made the warning go away, which makes sense. I was just hoping there was a better way. – myermian Jul 19 '12 at 10:14
  • If you are writing a library, then yeah I suppose it matters :) Most of us don't. In reality, if the expected consumers are the same language (c#) then there will be no problems using it, but it's not pretty for anyone down the line having to mark as non-cls compliant. – Andrew Aug 10 '12 at 02:50