IL2046: All interface implementations and method overrides must have annotations matching the interface or overriden virtual method 'RequiresUnreferencedCodeAttribute' annotations
Cause
There is a mismatch in the RequiresUnreferencedCodeAttribute annotations between an interface and its implementation or a virtual method and its override.
Example
A base member has the attribute but the derived member does not have the attribute.
public class Base
{
[RequiresUnreferencedCode("Message")]
public virtual void TestMethod() {}
}
public class Derived : Base
{
// IL2046: Base member 'Base.TestMethod' with 'RequiresUnreferencedCodeAttribute' has a derived member 'Derived.TestMethod()' without 'RequiresUnreferencedCodeAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
public override void TestMethod() {}
}
A derived member has the attribute but the overriden base member does not have the attribute.
public class Base
{
public virtual void TestMethod() {}
}
public class Derived : Base
{
// IL2046: Member 'Derived.TestMethod()' with 'RequiresUnreferencedCodeAttribute' overrides base member 'Base.TestMethod()' without 'RequiresUnreferencedCodeAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
[RequireUnreferencedCode("Message")]
public override void TestMethod() {}
}
An interface member has the attribute but its implementation does not have the attribute.
interface IRUC
{
[RequiresUnreferencedCode("Message")]
void TestMethod();
}
class Implementation : IRUC
{
// IL2046: Interface member 'IRUC.TestMethod()' with 'RequiresUnreferencedCodeAttribute' has an implementation member 'Implementation.TestMethod()' without 'RequiresUnreferencedCodeAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
public void TestMethod () { }
}
An implementation member has the attribute but the interface that it implements does not have the attribute.
interface IRUC
{
void TestMethod();
}
class Implementation : IRUC
{
[RequiresUnreferencedCode("Message")]
// IL2046: Member 'Implementation.TestMethod()' with 'RequiresUnreferencedCodeAttribute' implements interface member 'IRUC.TestMethod()' without 'RequiresUnreferencedCodeAttribute'. For all interfaces and overrides the implementation attribute must match the definition attribute.
public void TestMethod () { }
}
Maklum balas
Kirim dan lihat maklum balas untuk