IL3003: adnotacje "RequiresAssemblyFilesAttribute" muszą być zgodne ze wszystkimi implementacjami interfejsu lub przesłonięciami

Wartość
Identyfikator reguły IL3003
Kategoria Pojedynczy plik
Poprawka powodująca niezgodność lub niezgodność Nierozdzielający

Przyczyna

Podczas publikowania aplikacji jako pojedynczego pliku (na przykład przez ustawienie PublishSingleFile właściwości na true wartość w projekcie) implementacje interfejsu lub klasy pochodne z elementami członkowskimi, które nie mają pasujących adnotacji [RequiresAssemblyFiles] , mogą prowadzić do wywołania elementu członkowskiego z atrybutem, który nie jest zgodny z pojedynczym plikiem. Istnieją cztery możliwe scenariusze, w których można wygenerować ostrzeżenie:

  • Składowa klasy bazowej ma atrybut, ale zastępowanie składowej klasy pochodnej nie ma atrybutu:

    public class Base
    {
        [RequiresAssemblyFiles]
        public virtual void TestMethod() {}
    }
    public class Derived : Base
    {
        // IL3003: Base member 'Base.TestMethod' with 'RequiresAssemblyFilesAttribute' has a derived member 'Derived.TestMethod()' without 'RequiresAssemblyFilesAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
        public override void TestMethod() {}
    }
    
  • Składowa klasy bazowej nie ma atrybutu, ale zastępowanie składowej klasy pochodnej ma atrybut:

    public class Base
    {
        public virtual void TestMethod() {}
    }
    public class Derived : Base
    {
        // IL3003: Member 'Derived.TestMethod()' with 'RequiresAssemblyFilesAttribute' overrides base member 'Base.TestMethod()' without 'RequiresAssemblyFilesAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
        [RequiresAssemblyFiles]
        public override void TestMethod() {}
    }
    
  • Element członkowski interfejsu ma atrybut, ale jego implementacja nie ma atrybutu:

    interface IRAF
    {
        [RequiresAssemblyFiles]
        void TestMethod();
    }
    class Implementation : IRAF
    {
        // IL3003: Interface member 'IRAF.TestMethod()' with 'RequiresAssemblyFilesAttribute' has an implementation member 'Implementation.TestMethod()' without 'RequiresAssemblyFilesAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
        public void TestMethod () { }
    }
    
  • Element członkowski interfejsu nie ma atrybutu, ale jego implementacja ma atrybut :

    interface INoRAF
    {
        void TestMethod();
    }
    class Implementation : INoRAF
    {
        [RequiresAssemblyFiles]
        // IL3003: Member 'Implementation.TestMethod()' with 'RequiresAssemblyFilesAttribute' implements interface member 'INoRAF.TestMethod()' without 'RequiresAssemblyFilesAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
        public void TestMethod () { }
    }
    

Jak naprawić naruszenia

W przypadku wszystkich interfejsów i przesłonięć implementacja musi być zgodna z definicją pod względem obecności lub braku atrybutu "RequiresAssemblyFilesAttribute". Oba elementy członkowskie zawierają atrybut lub żaden z nich. Usuń lub dodaj atrybut w składowej interfejsu/klasy bazowej lub implementując/wyprowadzając składową klasy, tak aby atrybut był w obu lub nie.

Kiedy pomijać ostrzeżenia

Nie należy pomijać tego ostrzeżenia.