Constructor not CLS-compliant with TimeSpan argument and inheriting Attribute

581 Views Asked by At

Ok I'm stumped: why is a class not CLS-compliant when its only constructor has a System.TimeSpan argument and the class inherits from System.Attribute?

Here's a min-repro, plus proof that both System.Attribute and System.TimeSpan are CLS-compliant:

using System;

[assembly:CLSCompliant(true)]

namespace Test
{
    public class CLSCompliantClass1
    {
        public TimeSpan Foo; // CLS-compliant
        public CLSCompliantClass1(TimeSpan bar) { } // CLS-compliant
    }

    public class CLSCompliantClass2 : Attribute
    {
        public TimeSpan Foo; // CLS-compliant
        public CLSCompliantClass2(double foo) { } // CLS-compliant
    }

    public class NonCLSCompliantClass : Attribute
    {
        // 'Test.NonCLSCompliantClass' has no accessible constructors which use only CLS-compliant types
        public NonCLSCompliantClass(TimeSpan bar) { } // not CLS-compliant??
    }
}

To compile run:

>csc /t:library cls.cs /warnaserror /nologo
cls.cs(19,15): error CS3015: Warning as Error: 'Test.NonCLSCompliantClass' has no accessible constructors which use only CLS-compliant types

(repros with any /langversion:1..5)

0

There are 0 best solutions below