コードを完全に信頼して実行しているのに、メソッドのレイトバウンド呼び出しがMethodAccessExceptionをスローするという厄介な状況があります。状況は次のとおりです。
慣例によりいくつかのイベント処理ロジックをマップする基本クラスがあります。これらのハンドラーは、次のチュートリアルに従って、ILコードを発行することによって作成された動的メソッドを使用して呼び出されます。http://www.codeproject.com/KB/cs/dynamicmethoddelegates.aspx
//in AssemblyA.dll:
public abstract class Base : IEventHandler
{
protected static void RegisterDerivedType(Type derived)
{
//create list of delegates to invoke event handlers
}
void IEventHandler.Handle(IEvent e)
{
//late bound invocation of appropriate handler method (e.g. EventX
//or EventY)
//this code throws a MethodAccessException
}
}
//in assemblyB.dll
public class Derived : Base
{
static Derived()
{
RegisterDerivedType(typeof(Derived));
}
private void OnEventX(EventX e) //EventX is derived of IEvent
{ }
private void OnEventY(EventY e) //EventY is derived of IEvent
{ }
}
動的メソッドでプライベートメンバーを呼び出すことができないのはなぜですか?