For twenty years, lock (x) meant exactly one thing in IL: Monitor.Enter, a try, and a guarded Monitor.Exit. You could read the pattern in your sleep. C# 13 quietly broke that reflex. Lock over the new System.Threading.Lock type no longer calls Monitor at all — it calls EnterScope() and disposes a ref struct in a finally. The source still reads lock (x). The IL is a different shape entirely, and a decompiler that has not learned the new shape will either miss the lock or print a using that was never there.

The real question

The syntax did not change. Both of these are legal, and both read lock (_gate) { ... }:

private readonly object _gate = new(); // classic private readonly System.Threading.Lock _lock = new(); // C# 13 

The compiler looks at the static type of the operand. If it is System.Threading.Lock, it emits the new scope-based lowering. If it is anything else — object, a class, an interface — it falls back to the Monitor pattern that has existed since C# 1. Same keyword, two completely different expansions, selected by a type the decompiler has to recover first.

So the question is twofold. What does each lowering actually look like in IL? And given that the new one is structurally a ref struct acquired, used, and disposed in a finally — which is also exactly what using compiles to — how does a decompiler avoid printing the wrong statement?

The classic lowering

Start with the one every .NET engineer already knows. Locking a plain object:

public void Classic() { lock (_gate) { _count++; } } 

lowers, conceptually, to the familiar Monitor dance with a lockTaken flag so that an exception thrown between taking the monitor and entering the try cannot leak a held lock:

object obj = _gate; bool lockTaken = false; try { Monitor.Enter(obj, ref lockTaken); _count++; } finally { if (lockTaken) Monitor.Exit(obj); } 

The IL is unmistakable — two Monitor calls bracketing a protected region:

.locals init (object V_0, bool V_1) ldarg.0 ldfld object C::_gate stloc.0 ldc.i4.0 stloc.1 .try { ldloc.0 ldloca.s V_1 call void [System.Private.CoreLib]System.Threading.Monitor::Enter(object, bool&) // ... _count++ ... leave.s IL_end } finally { ldloc.1 brfalse.s IL_skip ldloc.0 call void [System.Private.CoreLib]System.Threading.Monitor::Exit(object) IL_skip: endfinally } 

The bool& lockTaken, the brfalse guard before Monitor.Exit, and the object-typed operand are the signature. Glass has matched this since day one.

The C# 13 lowering

Now the same body, but _lock is a System.Threading.Lock:

public void Scoped() { lock (_lock) { _count++; } } 

There is no Monitor, no lockTaken, no conditional exit. The compiler lowers this to an acquire-and-dispose over a ref struct:

System.Threading.Lock.Scope scope = _lock.EnterScope(); try { _count++; } finally { scope.Dispose(); } 

EnterScope() takes the lock and hands back a Lock.Scope — a ref struct nested inside Lock whose only job is to release the lock when disposed. Because Scope is a ref struct, it is stack-bound and the Dispose() in the finally is a direct, non-virtual call on its address. The IL:

.locals init (valuetype [System.Private.CoreLib]System.Threading.Lock/Scope V_0) ldarg.0 ldfld class [System.Private.CoreLib]System.Threading.Lock C::_lock callvirt instance valuetype [System.Private.CoreLib]System.Threading.Lock/Scope [System.Private.CoreLib]System.Threading.Lock::EnterScope() stloc.0 .try { // ... _count++ ... leave.s IL_end } finally { ldloca.s V_0 call instance void [System.Private.CoreLib]System.Threading.Lock/Scope::Dispose() endfinally } 

Two things jump out. First, the only method on the hot path is System.Threading.Lock::EnterScope(); Monitor never appears. Second, the finally is unconditional — there is no lockTaken flag, because EnterScope() either returns a valid Scope or throws, and a thrown EnterScope leaves nothing to release. The scope lowering is simpler than the Monitor lowering it replaces.

One keyword, two lowerings. The static type of the locked expression — not the syntax — decides which IL the compiler emits.

What Glass has to decide

The trap is that the scope lowering is byte-for-byte the shape of a using over a ref struct:

using System.Threading.Lock.Scope scope = _lock.EnterScope(); _count++; 

A ref struct disposable, held in a local, with Dispose() called in a finally — that is the textbook using pattern, and a decompiler that only matches "disposable in a finally" will print exactly that. It is not wrong IL-for-IL, but it is wrong C#: nobody wrote a using, and a Lock.Scope is not something you would ever using by hand because its entire reason to exist is the lock statement.

Glass disambiguates on the type pair, not the structure. The recogniser asks:

  1. Does the local being disposed in the finally have type System.Threading.Lock.Scope (the nested Scope inside System.Threading.Lock)?
  2. Was it produced by a call to System.Threading.Lock.EnterScope() immediately before the try?
  3. Is the finally a single unconditional Scope.Dispose() — no lockTaken, no other statements?

When all three hold, the acquire/try/finally collapse into one lock (_lock) { ... } and the Scope local vanishes. It was never in the source. Conversely, when Glass sees the Monitor.Enter(obj, ref lockTaken) / guarded Monitor.Exit(obj) pattern, it emits the same lock (_gate) { ... } from the other lowering. Both recover to the one keyword the programmer actually typed — which is the whole point. The source does not record which lowering was used; only the operand's type does, and Glass carries that type through so the output recompiles to the same IL.

Why getting it wrong matters

Rendering a System.Threading.Lock lock as using var scope = _lock.EnterScope(); is more than cosmetic. It hides a lock from anyone auditing the code for concurrency, and it invites a "cleanup" refactor that drops the using and silently removes mutual exclusion. The inverse error is subtler: if a decompiler recovered a System.Threading.Lock lock but re-emitted it as lock over an operand it had re-typed to object, the recompiled code would bind to Monitor instead of EnterScope — a real behavioral change, since the two locks do not interoperate. Preserving the operand's exact type is what keeps the round-trip honest.

When it breaks

The recovery is exact on clean assemblies, with two honest edges. If the target was built against a shim or a runtime where System.Threading.Lock is absent, the Scope type does not resolve and Glass falls back to the literal EnterScope()/Dispose() form in a using, with the IL view one click away so you can confirm the intent. And if an obfuscator has reordered the finally or hoisted the Scope local across blocks so the acquire no longer sits directly before the try, the structural match can miss; Glass then shows the raw EnterScope/Dispose pair, which still reads clearly as a lock. For your own code with symbols, none of that arises — you get lock (_lock) back, verbatim.

Takeaway

C# 13 is the first time in two decades that lock means something new at the IL level, and it will not be the last build you decompile that uses it. The giveaway is the type pair: System.Threading.Lock.EnterScope() returning a Lock.Scope that is Dispose()d in a finally, with no Monitor and no lockTaken flag anywhere. Glass keys on that pair, folds the scope away, and gives you back the lock statement instead of a misleading using — while still recovering the classic Monitor lowering from plain-object locks. Decompile your own .NET 9 code with Glass, free, and read the decompilation docs for how the statement recognisers are wired.