Mono.Cecil:操作可能在运行时不稳定

发布于 2024-10-14 04:33:04 字数 1275 浏览 10 评论 0原文

我遵循此处的提示,我什至将以下几行放入:

var MSILWorker = prop.SetMethod.Body.GetILProcessor();
MSILWorker.Body.InitLocals = true;

我在两个类中有两个属性

 [NotifyProperty]
 public int Number { get; set; }

 [NotifyProperty]
 public string Name { get; set; }

: 生成的 IL 代码完全相同,当然除了属性名称和支持字段的类型之外。然而第一个抛出 VerificationException (“操作可能会破坏运行时的稳定性”),第二个则不会。 我可能做错了什么?

编辑:这是有问题的IL:

.method public hidebysig specialname instance void set_Number(int32 'value') cil managed
{
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
    .maxstack 3
    L_0000: nop 
    L_0001: ldarg.0 
    L_0002: ldarg.1 
    L_0003: stfld int32 TestApplication.SLTest.SLBOComposite::<Number>k__BackingField
    L_0008: ldarg.0 
    L_0009: ldstr "Number"
    L_000e: call instance void TestApplication.SLTest.SLBOComposite::RaisePropertyChanged(string)
    L_0013: nop 
    L_0014: ldarg.0 
    L_0015: ldstr "Number"
    L_001a: ldarg.1 
    L_001b: call instance void W3B.TestApplication.SLTest.SLBOComposite::Validate(string, object)
    L_0020: nop 
    L_0021: ret 
}

I followed the hints here, I even put the following lines in:

var MSILWorker = prop.SetMethod.Body.GetILProcessor();
MSILWorker.Body.InitLocals = true;

I have two properties in two classes:

 [NotifyProperty]
 public int Number { get; set; }

and

 [NotifyProperty]
 public string Name { get; set; }

The generated IL code is perfectly identical, except of course in the name of the properties and the type of the backing field. Yet the first one throws VerificationException (“Operation could destabilize the runtime”), the second one does not.
What could have I possibly done wrong?

edit: here is the offending IL:

.method public hidebysig specialname instance void set_Number(int32 'value') cil managed
{
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
    .maxstack 3
    L_0000: nop 
    L_0001: ldarg.0 
    L_0002: ldarg.1 
    L_0003: stfld int32 TestApplication.SLTest.SLBOComposite::<Number>k__BackingField
    L_0008: ldarg.0 
    L_0009: ldstr "Number"
    L_000e: call instance void TestApplication.SLTest.SLBOComposite::RaisePropertyChanged(string)
    L_0013: nop 
    L_0014: ldarg.0 
    L_0015: ldstr "Number"
    L_001a: ldarg.1 
    L_001b: call instance void W3B.TestApplication.SLTest.SLBOComposite::Validate(string, object)
    L_0020: nop 
    L_0021: ret 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小鸟爱天空丶 2024-10-21 04:33:04

没关系。 :)

 L_001b: box int32

有解决方案。

Never mind. :)

 L_001b: box int32

There is the solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文