Edit

Share via


Compiler Error CS0447

Attributes cannot be used on type arguments, only on type parameters

This error occurs when you apply an attribute to a type argument that occurs in an invocation statement. It is acceptable to apply an attribute to a type parameter in a class or method declaration statement such as the following:

C#
class C<[some attribute] T> {…}

The following line of code will generate this error. It is assumed that the class C, defined in the previous line of code, has a static method called MyStaticMethod.

C#
C<[some attribute] T>.MyStaticMethod();

Example

The following code generates error CS0447:

C#
// CS0447.cs
using System;

namespace Test41
{
    public interface I<A>
    {
        void Meth<B>();
    }
    public class B : I<int>
    {
        void I<[Test] int>.Meth<X>() { }  // CS0447
    }
}

Note

This compiler error is no longer used in Roslyn.