.net 在Silverlight中使用DynamicMethod时的验证异常
我想通过委托调用某些方法,但得到VerificationException。我正在使用以下代码:.net 在Silverlight中使用DynamicMethod时的验证异常,.net,silverlight,dynamicmethod,.net,Silverlight,Dynamicmethod,我想通过委托调用某些方法,但得到VerificationException。我正在使用以下代码: internal delegate void Delegete_add_Startup(object o, StartupEventHandler s); Delegete_add_Startup del; public App() { //this.Startup += this.Application_Startup; Type
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\u Startup
通过使用上述代码的代表
这会产生一个VerificationException:操作可能会破坏运行时异常的稳定性
通过将此代码放在全新Silverlight应用程序项目的应用程序构造函数中,可以很容易地复制此代码。
我做错了什么?对于您的情况,您可以替换操作码。按操作码调用。CallVirt,它应该工作得更好(未经测试和理解,我是Silverlight CLR的新手)。我遇到了同样的问题。你找到线索了吗?即使使用一个非常简单的操作码。调用而没有任何参数和返回值,我也会遇到问题。