Skip to main content

Generic class cannot derive from Attribute

In This Article

CodeRush Classic shows the Generic class cannot derive from Attribute code issue if a generic class derives from an attribute class.

#Fix

Remove an attribute class from the current class ancestors or make the current class non-generic.

#Purpose

Highlights the generic class declaration statements, which would cause the A generic type cannot derive from ‘Class name’ class because it is an attribute class compilation error.

#Example

public class MyClass<T>: Attribute
{

}

Fixes:

public class MyClass<T>
{

}
public class MyClass: Attribute
{

}