Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Cecil:操作可能在运行时不稳定_C#_Inotifypropertychanged_Cil_Mono.cecil - Fatal编程技术网

C# Cecil:操作可能在运行时不稳定

C# Cecil:操作可能在运行时不稳定,c#,inotifypropertychanged,cil,mono.cecil,C#,Inotifypropertychanged,Cil,Mono.cecil,我按照提示,甚至写了以下几行: var MSILWorker = prop.SetMethod.Body.GetILProcessor(); MSILWorker.Body.InitLocals = true; 我在两个类中有两个属性: [NotifyProperty] public int Number { get; set; } 及 生成的IL代码完全相同,当然除了属性的名称和支持字段的类型。然而第一个抛出了VerificationException(“操作可能会破坏运行时的稳定性”

我按照提示,甚至写了以下几行:

var MSILWorker = prop.SetMethod.Body.GetILProcessor();
MSILWorker.Body.InitLocals = true;
我在两个类中有两个属性:

 [NotifyProperty]
 public int Number { 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 
}
.method public hidebysing specialname实例void set\u Number(int32'值)cil托管
{
.custom instance void[mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
.maxstack 3
L_0000:没有
L_0001:ldarg.0
L_0002:ldarg.1
L_0003:stfld int32 TestApplication.SLTest.SLBOComposite::k_BackingField
L_0008:ldarg.0
L_0009:ldstr“编号”
L_000e:调用实例void TestApplication.SLTest.SLBOComposite::RaisePropertyChanged(字符串)
L_0013:没有
L_0014:ldarg.0
L_0015:ldstr“编号”
L_001a:ldarg.1
L_001b:调用实例void W3B.TestApplication.SLTest.SLBOComposite::Validate(字符串,对象)
L_0020:没有
L_0021:ret
}
没关系。:)

这就是解决办法

.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 
}
 L_001b: box int32