デリゲートを介して特定のメソッドを呼び出したいのですが、VerificationExceptionが発生しています。私は次のコードを使用しています:
internal delegate void Delegete_add_Startup(object o, StartupEventHandler s);
Delegete_add_Startup del;
public App()
{
//this.Startup += this.Application_Startup;
Type[] parameterTypes = new Type[2];
parameterTypes[0] = typeof(object);
parameterTypes[1] = typeof(StartupEventHandler);
MethodInfo mi = typeof(Application).GetMethod("add_Startup", BindingFlags.Public | BindingFlags.Instance);
DynamicMethod method = new DynamicMethod(string.Empty, mi.ReturnType, parameterTypes);
method.InitLocals = true;
ILGenerator iLGenerator = method.GetILGenerator();
iLGenerator.Emit(OpCodes.Ldarg_0);
iLGenerator.Emit(OpCodes.Ldarg_1);
iLGenerator.Emit(OpCodes.Call, mi);
iLGenerator.Emit(OpCodes.Ret);
del = (Delegete_add_Startup)method.CreateDelegate(typeof(Delegete_add_Startup));
del(this, new StartupEventHandler(Application_Startup));
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
}
基本的に、私は電話しようとしています
this.Startup + = this.Application_Startup;
上記のコードを使用してデリゲートを介して。
これにより、VerificationExceptionが発生します。操作によってランタイム例外が不安定になる可能性があります。
このコードを新しいSilverlightアプリプロジェクトのアプリコンストラクターに配置することで、これを非常に簡単に再現できます。私は何が間違っているのですか?