Export (0) Print
Expand All
Expand Minimize

Compiler Warning CS3024

Visual Studio 2008

Constraint type 'type' is not CLS-compliant.

The compiler issues this warning because the use of a non-CLS-compliant type as a generic type constraint could make it impossible for code written in some languages to consume your generic class.

To eliminate this warning

  • Use a CLS-compliant type for the type constraint.

The following example generates CS3024 in several locations:

// cs3024.cs
// Compile with: /target:library
 [assembly: System.CLSCompliant(true)]

[type: System.CLSCompliant(false)]
public class TestClass // CS3024
{
    public ushort us;
}
[type: System.CLSCompliant(false)]
public interface ITest // CS3024
{}
public interface I<T> where T : TestClass
{}
public class TestClass_2<T> where T : ITest
{}
public class TestClass_3<T> : I<T> where T : TestClass
{}
public class TestClass_4<T> : TestClass_2<T> where T : ITest
{}
public class Test
{
    public static int Main()
    {
        return 0;
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft