The “VariableDefinition” class contains a field “index” which stores the index of the variable in the list of variables for its method.
If I’m not mistaken, when Mono.Cecil writes out the assembly, it blindly trusts this index field. This means that reordering the MethodBody.Variables collection causes the wrong indexes to be output. I think Mono.Cecil.Cil.CodeWriter should recompute the indexes before writing the method body, either in WriteInstructions() or earlier in ComputeHeader(), or perhaps in a new method of its own called from WriteResolvedMethodBody()? -- -- mono-cecil
