---
title: "ILSpy: C# and VB decompiler fixes in .NET | VulCode"
description: "Seven fixes to the ILSpy .NET decompiler in C#: VB exception filters, with expressions that await, ?. chains and nint conditionals, so output compiles again."
url: "https://vulcode.com/en/opensource/contributions/ilspy"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

icsharpcode/ILSpy

# ILSpy

An open source .NET decompiler that turns compiled assemblies back into readable C# code. It is used to inspect libraries whose source code is not at hand.

[See the repository](https://github.com/icsharpcode/ILSpy) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: C#
- **GitHub stars**: 27,138
- **Merged changes**: 7

## What we changed

We fixed seven cases where the decompiler produced code that did not compile or read worse than the source: from Visual Basic exception filters, through await on a type parameter and with expressions that await, to ?. chains over bool? and nint conditionals.

### What this work shows

- IL analysis and Roslyn patterns

- async/await state machines

- Visual Basic exception filters

- Compile round-trip tests

What was broken

### A VB exception filter caught object, not Exception

The VB compiler writes the filter for On Error Resume Next and On Error GoTo as a single and expression, not as the branch chain the C# compiler emits. ILSpy did not know that shape and printed catch (object obj) when (obj is Exception && ...).

How we fixed it

### The type test moves into the catch declaration

The decompiler now recognises this pattern, takes the type test out of the condition and prints catch (Exception ex) when (...) with the condition alone. Tests for On Error and Visual Basic try, catch and finally blocks were added.

[#4134](https://github.com/icsharpcode/ILSpy/pull/4134)

What was broken

### Decompiled code kept the delegate cache field

With _ = (Action<int>)M; the delegate is created and discarded at once, so the cache field is never read. The transform required exactly one read, so the output kept a field named <>O.<0>__M and the code did not compile.

How we fixed it

### The delegate construction instead of the cache check

When the cache field has no reads, the check is replaced by the delegate construction it guarded. The output is new Action<int>(M);, which compiles and does the same.

[#4133](https://github.com/icsharpcode/ILSpy/pull/4133)

What was broken

### Conditionals lost nint and their local

After an earlier change in the decompiler, two patterns came out worse than the source. A ?: with nint branches of different types got (IntPtr) casts, and int n = b? 1: 0; from code built with -o+ was pasted into every use of n.

How we fixed it

### nint and the local stay in place

VisitIfInstruction maps IntPtr to nint when native integers are on, with the same logic VisitBox uses. CopyPropagation no longer copies between a bool and a non-bool variable, so the conditional stays in its local.

[#4231](https://github.com/icsharpcode/ILSpy/pull/4231) [#4232](https://github.com/icsharpcode/ILSpy/pull/4232)

What was broken

### await on a type parameter dropped its operand

With await value, where T is constrained to an interface with GetAwaiter, the constrained call becomes an LdObjIfRef instruction. ExpressionBuilder had no case for it, so the output had an unsupported opcode comment instead of value and did not compile.

How we fixed it

### The await operand is translated from its address

The await operand is now translated from its address, the way CallBuilder already does for call receivers. The output is await value; again, with a test in AsyncAwaitPatterns.

[#4251](https://github.com/icsharpcode/ILSpy/pull/4251)

What was broken

### A ?. chain over bool? failed to compile

The decompiler turned GetValueOrDefault() on a bool? into == true even inside a ?. chain. The chain ended too early, the result was bool instead of bool?, and the ?? false after it did not compile.

How we fixed it

### GetValueOrDefault() stays inside the ?. chain

The call is kept as it is when its target is part of a ?. chain, so the output is c?.Flag.GetValueOrDefault() ?? false. We added a test for the printed output and one that runs both forms on null, false and true.

[#4253](https://github.com/icsharpcode/ILSpy/pull/4253)

What was broken

### with plus await left a raw <Clone>$ call

When a with expression's initializer contained an await, Roslyn copies the receiver into a hoisted temporary before the await. The initializer transform rejected that copy, so the output kept a _003CClone_003E_0024() call and separate assignments that did not compile.

How we fixed it

### The with expression is rebuilt with its await

ILInlining now inlines copies between two hoisted compiler temporaries and leaves copies of user locals alone. The output is value with { X = await Get() } again, and the same works for object initializers.

[#4292](https://github.com/icsharpcode/ILSpy/pull/4292)

## Merged changes 7

- [#4292 Fix #4019: Recognize with expressions whose initializer awaits Merged 8 November 2026](https://github.com/icsharpcode/ILSpy/pull/4292)

- [#4253 Fix #3702: Don't rewrite GetValueOrDefault() to == true in ?. chains Merged 17 October 2026](https://github.com/icsharpcode/ILSpy/pull/4253)

- [#4251 Fix #4017: Look through LdObjIfRef on the operand of await Merged 16 October 2026](https://github.com/icsharpcode/ILSpy/pull/4251)

- [#4231 Fix #4135: Keep bool-to-int conditional in its local Merged 16 October 2026](https://github.com/icsharpcode/ILSpy/pull/4231)

- [#4232 Fix #4137: Keep nint in conditionals with mixed native int branches Merged 11 October 2026](https://github.com/icsharpcode/ILSpy/pull/4232)

- [#4133 Remove the delegate cache left by a discarded method-group conversion Merged 19 September 2026](https://github.com/icsharpcode/ILSpy/pull/4133)

- [#4134 Recognize a VB exception filter's type test Merged 15 September 2026](https://github.com/icsharpcode/ILSpy/pull/4134)

## What it taught us

Changing one transform in a decompiler easily breaks other patterns, so you have to read the IL that Roslyn and the VB compiler actually emit. Each change has a test that compiles a sample, decompiles it and compares the result with the original.

[More about this technology: C# and .NET](https://vulcode.com/en/technologies/csharp-and-dotnet)

## Other projects we write code for

- [**OpenRA** C# · 17,827 stars An open source real-time strategy engine for classic Westwood games such as Command & Conquer: Red Alert, written in C# with SDL and OpenGL.](https://vulcode.com/en/opensource/contributions/openra)

- [**Polly** C# · 14,255 stars A .NET library for handling transient faults: retries, circuit breakers, timeouts and fallback. Its Simmy module injects faults on purpose to test how an application copes with them.](https://vulcode.com/en/opensource/contributions/polly)

- [**FluentValidation** C# · 9,780 stars A popular .NET library for writing strongly typed validation rules in a fluent style, such as RuleFor(...).InclusiveBetween(...).](https://vulcode.com/en/opensource/contributions/fluentvalidation)

- [**Serilog** C# · 8,064 stars A structured logging library for .NET. It records events from message templates, with named properties rather than plain text.](https://vulcode.com/en/opensource/contributions/serilog)

- [**NLog** C# · 6,547 stars A flexible structured logging library for many .NET platforms, configured through layouts, filters and targets.](https://vulcode.com/en/opensource/contributions/nlog)

- [**Markdig** C# · 5,359 stars A fast CommonMark-compliant Markdown processor for .NET, with extensions such as tables, definition lists and automatic heading identifiers.](https://vulcode.com/en/opensource/contributions/markdig)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
