We have the following method in the classroom in one of our projects:
private unsafe void SomeMethod() {
I had to obfuscate it, but I hope it is still clear enough to understand what is happening.
On one of our developers' machines in debug builds, the C # compiler deletes three assignments that occur after the fixed block is closed. If we try to put a breakpoint on these lines, the breakpoint goes to the end bracket of the method when the application starts. The code that appears between the fixed block and the end of the method is also deleted in other methods, but with bewilderment, but not in all of them.
After some experimentation, we found that enabling optimization for the affected project caused the inclusion of missing code. However, this work is not suitable for our unit testing - the code is missing, and changing the optimization of the affected project and its test project does not help. We also found that moving the three assignments within the internal fixed statement worked - it becomes clear why in the analysis of IL.
In a debugging DLL built on the affected machine (with optimization disabled), the returned op appears immediately after ap popped up from the stack:
IL_03a1: nop IL_03a2: ldc.i4.0 IL_03a3: conv.u IL_03a4: stloc.s ap IL_03a6: ret
This explains why moving the three assignments before the stloc . In a debugging DLL built on my machine, the returned op occurs in the expected place after three assignments:
IL_03a5: nop IL_03a6: ldc.i4.0 IL_03a7: conv.u IL_03a8: stloc.s ap IL_03aa: nop IL_03ab: ldc.i4.0 IL_03ac: conv.u IL_03ad: stloc.s tp IL_03af: nop IL_03b0: ldc.i4.0 IL_03b1: conv.u IL_03b2: stloc.s vp IL_03b4: ldarg.0 IL_03b5: ldloc.s nts IL_03b7: stfld string[] NBEB::ts IL_03bc: ldarg.0 IL_03bd: ldloc.s nttp IL_03bf: stfld valuetype [SharpDX]SharpDX.Vector2[] NBEB::ttp IL_03c4: ldarg.0 IL_03c5: ldloc.s nv IL_03c7: call instance void NBEB::set_V(valuetype [SharpDX]SharpDX.Vector4[]) IL_03cc: nop IL_03cd: ret
We still have not been able to create SSCCE - this, apparently, is manifested only in special circumstances and only in one of our projects. We checked that the same versions of Visual Studio, .NET framework, C # compiler and MSBuild are used on both machines. We checked for other potential differences, such as OS version and updates. On both machines, everything is the same (this is the same laptop model). I am a little puzzled, to be honest. Any help would be greatly appreciated.