Menu

How await using decompiles in C#
πŸ“°

How await using decompiles in C#

DEV Community: csharpΒ·Zero HeartbeatΒ·10 days ago
#Gy7SSKO7
#devtocsharp#devto#dev#await#disposal
Long article (1322 words) β€” no AI summary yet.
Reading 0:00
15s threshold

A finally block that contains await is impossible at the IL level. A protected region is a pair of metadata offsets that must bracket one contiguous run of instructions, and an await tears the method in two β€” MoveNext returns at the suspension point and re-enters later at a different state. There is no single range to protect. Yet await using exists, and its entire purpose is to call DisposeAsync from a finally . The compiler resolves the contradiction by dissolving the finally: it rewrites the disposal into ordinary branches woven into the state machine, so every path that leaves the guarded body runs the disposal inline first. Decompiling the result means recognizing that dissolved shape and reassembling the await using that produced it.

The real question

Here is the source we will recover:

async Task CopyAsync ( Stream src ) { await using var dst = File . Create ( "out.bin" ) ; await src .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.