It looks like a reflector error: it's just a normal volatile reading of the s_barrier field. There is no "special" IL that is not expressed in C #.
L_000d: volatile. L_000f: ldsfld object modreq(System.Runtime.CompilerServices.IsVolatile) System.Threading.LazyInitializer::s_barrier
This is regular code that the compiler emits when reading from a static unstable field.
Itβs easier to reproduce here: just compile the following (wrapped in type) in release mode:
private static volatile object field; private static void Main() { var temp = field; }
Reflector creates the following decompiled C #:
private static void Main() { volatile object field = Program.field; }
when IL really:
L_0000: volatile. L_0002: ldsfld object modreq([mscorlib]System.Runtime.CompilerServices.IsVolatile) WindowsFormsApplication1.Program::field L_0007: pop L_0008: ret
UPDATE : Here I guess what happens: in release mode, the C # compiler optimizes the distribution of the field value (the result of a mutable read) to a local variable ( stloc instruction), since the local one is not used later, It seems to confuse the reflector. If you changed the method of using subsequent use of local, the stloc command (or similar) would indeed stloc , after which the decompiled output from Reflector would look reasonable.
source share