原因
インターフェイスとその実装、または仮想メソッドとそのオーバーライド間で RequiresUnreferencedCodeAttribute 注釈に不一致があります。
例
ベース メンバーには属性がありますが、派生メンバーには属性がありません。
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() {}
}
派生メンバーには属性がありますが、オーバーライドされたメンバーには属性がありません。
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() {}
}
インターフェイス メンバーには属性がありますが、その実装には属性がありません。
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 () { }
}
実装メンバーには属性がありますが、実装するインターフェイスには属性がありません。
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 () { }
}
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET