I was trying to make an exemple more representative of what we try to do following to my
post.
I'm front of another incomprehension. The key of the problem is here, in this assembly :
It is valid IL, and the result is peverified. Notice that the assignement of int(2) if it can look tricky is nothing more than AnEnumeration.B. Anyway as an enum is a valuetype, the CLR only manipulates integers when using this AnEnumeration.
I've used ilasm to produce an assembly 3.dll.
I next wrote a little program that use this assembly, 4.exe :
It is simple. In my head, I expect the result to be True. What do you think ?
But no, it is not, executing this on ms .net framework 1.1, it prints False.
I've open the 4.exe assembly in ildasm, here is the result :
What does it means ? It means that we first push the value of the field on the stack, then when push AnEnumeration.B on the stack, here csc have made a shortcut, and push directly 2, then we find the ceq opcode. The ceq operand mean "Compare Equals". It will compare the last two values from the stack, and push 1 if they are equals, 0 if not. Here it put 0, that is boxed in Boolean to be printed as False.
So the value of the field is not 2. The snippet 5.exe will convince you :
The ouput is 2 == 0 => False.
We can reproduce the same problem using Reflection to read the value of the field.
For the MS .net Framework, its value is 0, not 2. But why ???
Once again, every pieces of code works perfeclty, with the expected behavior on Mono.
For Mono the value of the field is 2, not 0.
It is not a great problem for us because we use Rail to read the library, that do not use System.Reflection. But it can be a problem for someone else.
Anyway we then have the problem described in the previous
post, to set the constant value 2 on the field.