Niestandardowa wersja elementu "System.Runtime.CompilerServices.ExtensionAttribute" znaleziona przez kompilator jest nieprawidłowa

Niestandardowa wersja elementu "System.Runtime.CompilerServices.ExtensionAttribute" znaleziona przez kompilator jest nieprawidłowa. Flagi użycia atrybutu muszą być ustawione tak, aby zezwalać na zestawy, klasy i metody.

Niestandardowa wersja odnalezionego System.Runtime.CompilerServices.ExtensionAttribute kompilatora nie ustawia flag użycia atrybutów, aby umożliwić stosowanie atrybutu do zestawów, metod i klas. Aplikacja do co najmniej tych trzech elementów programu jest wymagana.

Identyfikator błędu: BC36558

Aby poprawić ten błąd

Przykład

W poniższym przykładzie użyto atrybutu AttributeUsage , aby określić, do których elementów programu można zastosować nową wersję ExtensionAttribute programu. W przykładzie AttributeTargets określono trzy elementy członkowskie wyliczenia: Assembly, Classi Method. Pominięcie któregokolwiek z tych elementów spowoduje ten błąd.

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

Alternatywnie można zezwolić ExtensionAttribute na zastosowanie do wszystkich elementów programu przy użyciu All elementu członkowskiego AttributeTargets.

<AttributeUsage(AttributeTargets.All)>

Usunięcie AttributeUsage wiersza, jak pokazano w poniższym kodzie, daje ten sam wynik.

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

Zobacz też