The custom-designed version of 'System.Runtime.CompilerServices.ExtensionAttribute' found by the compiler is not valid

The custom-designed version of 'System.Runtime.CompilerServices.ExtensionAttribute' found by the compiler is not valid. Its attribute usage flags must be set to allow assemblies, classes, and methods.

The custom-designed version of System.Runtime.CompilerServices.ExtensionAttribute that the compiler found does not set its attribute usage flags to enable application of the attribute to assemblies, methods, and classes. Application to at least those three program elements is required.

Error ID: BC36558

To correct this error

Example

The following example uses the AttributeUsage attribute to specify which program elements the new version of ExtensionAttribute can apply to. The example specifies three members of the AttributeTargets enumeration: Assembly, Class, and Method. The omission of any one of these elements will cause this error.

Namespace System.Runtime.CompilerServices
    <AttributeUsage(AttributeTargets.Assembly Or _
        AttributeTargets.Class Or AttributeTargets.Method)>
    Class ExtensionAttribute
        Inherits System.Attribute
        ' Definitions of methods, fields, and properties.
    End Class
End Namespace

Alternatively, you could allow ExtensionAttribute to apply to all program elements by using the All member of AttributeTargets.

    <AttributeUsage(AttributeTargets.All)>

Deleting the AttributeUsage line, as shown in the following code, produces the same result.

Namespace System.Runtime.CompilerServices
    Class ExtensionAttribute
        Inherits System.Attribute
        ' Definitions of methods, fields, and properties.
    End Class
End Namespace

See Also

Tasks

How to: Define Your Own Attributes

Concepts

Attributes Overview in Visual Basic

Extension Methods (Visual Basic)

Writing Custom Attributes

Reference

ExtensionAttribute

Other Resources

Custom Attributes in Visual Basic