Редагувати

Поділитися через


IL3003: 'RequiresAssemblyFilesAttribute' annotations must match across all interface implementations or overrides

Value
Rule ID IL3003
Category SingleFile
Fix is breaking or nonbreaking Nonbreaking

Cause

When you publish an app as a single file (for example, by setting the PublishSingleFile property to true in a project), interface implementations or derived classes with members that don't have matching annotations of [RequiresAssemblyFiles] can lead to calling a member with the attribute, which is not single-file compatible. There are four possible scenarios where the warning can be generated:

  • A member of a base class has the attribute but the overriding member of the derived class doesn't have the attribute:

    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() {}
    }
    
  • A member of a base class doesn't have the attribute but the overriding member of the derived class does have the attribute:

    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() {}
    }
    
  • An interface member has the attribute but its implementation doesn't have the attribute:

    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 () { }
    }
    
  • An interface member doesn't have the attribute but its implementation does have the attribute:

    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 () { }
    }
    

How to fix violations

For all interfaces and overrides, the implementation must match the definition in terms of the presence or absence of the 'RequiresAssemblyFilesAttribute' attribute. Either both the members contain the attribute or neither of them. Remove or add the attribute on the interface/base class member or implementing/deriving class member so that the attribute is on both or neither.

When to suppress warnings

You should not suppress this warning.