编译器找到的“System.Runtime.CompilerServices.ExtensionAttribute”自定义设计版本无效

编译器找到的“System.Runtime.CompilerServices.ExtensionAttribute”自定义设计版本无效。 其特性使用标志必须设置为允许程序集、类和方法。

编译器找到的 System.Runtime.CompilerServices.ExtensionAttribute 的自定义设计的版本没有设置其特性使用标志,以向程序集、方法和类启用该特性的应用程序。 至少这三个程序元素的应用程序是必需的。

错误 ID: BC36558

更正此错误

示例

下面的示例使用 AttributeUsage 特性来指定可向其应用 ExtensionAttribute 新版本的程序元素。 该示例指定 AttributeTargets 枚举的三个成员: AssemblyClassMethod。 省略这些元素中的任何一个都将导致此错误。

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

或者,你可以通过使用 ExtensionAttributeAll 成员,允许 AttributeTargets应用于所有程序元素。

<AttributeUsage(AttributeTargets.All)>

删除 AttributeUsage 行(如下面的代码中所示)将产生相同的结果。

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

另请参阅