Export (0) Print
Expand All
Expand Minimize

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:

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<[some attribute] T>.MyStaticMethod();

The following code generates error CS0447.

// 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

Community Additions

© 2014 Microsoft