# Decompiling a VB.NET assembly to C#


You inherit a `.dll`. It is part of a line-of-business app that has run for fifteen years, the source was last seen on a developer's machine that was decommissioned a decade ago, and the only clue to its origin is that everyone who remembers it calls it "the VB component." You open it in a decompiler expecting Visual Basic, and out comes C# — C# littered with calls to types you have never written: `NewLateBinding.LateGet`, `Operators.CompareString`, `Conversions.ToDouble`, `ProjectData.SetProjectError`.

That is not the decompiler guessing wrong. It is the decompiler being honest. The CLR has no idea your assembly was once Visual Basic — metadata and IL carry no source-language tag — but the VB compiler left fingerprints everywhere, and those fingerprints *are* those helper calls. This post walks through what the Visual Basic compiler did to your code on its way to IL, and how [Glass.NET](https://delta1labs.com/products/glass) — the free, static-only .NET decompiler — turns a binary that was never C# into C# you can actually read.

## Metadata has no language; the compiler has an accent

C# and Visual Basic both target the same CLR. By the time MSBuild is done, a VB project and a C# project produce the same kind of PE file: a type system described in metadata tables, methods described in IL. There is no "this was VB" flag. A decompiler therefore always reconstructs C#, because C# is the language that maps most directly onto the metadata — and that is exactly what you want when the goal is to *read* the thing.

But each compiler has an accent. The VB compiler reaches for the Visual Basic runtime, `Microsoft.VisualBasic.dll`, to implement language features the CLR does not provide natively. Learn to hear the accent and the decompiled C# stops looking strange and starts telling you precisely what the original VB said.

## Modules become sealed static classes

A VB `Module` has no direct C# equivalent, so the compiler lowers it into a sealed class whose members are all `static`, tagged with a marker attribute. This VB:

```vb
Module Billing
    Public Function NetTotal(gross As Double, taxRate As Double) As Double
        Return gross / (1 + taxRate)
    End Function
End Module
```

compiles to a type carrying `Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute`, with the method emitted as:

```
.class public auto ansi sealed Billing
    extends [System.Runtime]System.Object
{
  .custom instance void [Microsoft.VisualBasic]...StandardModuleAttribute::.ctor()
  .method public static float64 NetTotal(float64 gross, float64 taxRate) ...
}
```

Glass recognises the `StandardModule` marker and the all-static shape and reconstructs the idiomatic C# equivalent — a `static class` — rather than an abstract-sealed oddity:

```csharp
[StandardModule]
internal static class Billing
{
    public static double NetTotal(double gross, double taxRate)
        => gross / (1.0 + taxRate);
}
```

The `[StandardModule]` attribute is left visible deliberately: it is the single clearest fingerprint that the original was a VB `Module`, and hiding it would erase information you may need.

## Late binding: the `Option Strict Off` tax

Nothing marks a VB assembly like late binding. Under the default `Option Strict Off`, this is perfectly legal VB:

```vb
Public Function TitleOf(doc As Object) As String
    Return doc.Metadata.Title
End Function
```

`doc` is typed `Object`, and `.Metadata.Title` is resolved at runtime by reflection. C# would need `dynamic` for this — but the VB compiler does not emit a `dynamic` call site. It emits a call into the Visual Basic runtime's late binder. The IL for `doc.Metadata.Title` becomes two `NewLateBinding.LateGet` calls, and Glass reconstructs them faithfully:

```csharp
public static string TitleOf(object doc)
{
    object metadata = NewLateBinding.LateGet(
        doc, null, "Metadata", new object[0], null, null, null);
    return Conversions.ToString(
        NewLateBinding.LateGet(
            metadata, null, "Title", new object[0], null, null, null));
}
```

That is verbose, but it is the truth: every member access on a late-bound `Object` was a reflective lookup, and the decompiled C# shows exactly that. When you see `NewLateBinding.LateGet` or `LateCall`, you are reading code that was written with `Option Strict Off`. Mentally, `LateGet(x, null, "P", …)` is just `((dynamic)x).P` — Glass gives you a menu option to collapse recognised late-binding calls into `dynamic` member access when you would rather read intent than mechanism.

## String comparison goes through `Operators.CompareString`

In C#, `a == b` on two strings is an ordinal-ish `string.Equals`. In VB, the `=` operator on strings depends on `Option Compare`, and the compiler never emits a direct comparison. It emits `Operators.CompareString`, which takes a third argument — `TextCompare` — that is `false` for `Option Compare Binary` and `true` for `Option Compare Text` (case-insensitive, culture-aware). So this VB:

```vb
If status = "Active" Then Return True
```

decompiles to:

```csharp
if (Operators.CompareString(status, "Active", TextCompare: false) == 0)
    return true;
```

The third argument is diagnostic gold. `TextCompare: true` means the whole module was compiled with `Option Compare Text`, and every string `=` in it was a case-insensitive compare — a behaviour you would badly want to preserve if you ever port this code to C#, where `==` would silently become case-sensitive. Glass surfaces the flag rather than dropping it.

## `On Error` becomes `ProjectData` bookkeeping

VB's unstructured error handling — `On Error Resume Next`, `On Error GoTo` — has no IL instruction behind it. The compiler synthesises a state machine around the Visual Basic runtime's `ProjectData` error registry. A method with `On Error Resume Next` decompiles into a `try`/`catch` skeleton with `ProjectData.SetProjectError(ex)` in the catch and `ProjectData.ClearProjectError()` where control resumes, plus a hidden integer tracking the "resume" target. Glass reconstructs the control flow accurately — you can see which statements were protected and where execution was meant to resume — even though the original `On Error` keyword is gone. Seeing `ProjectData.SetProjectError` in a `catch` block is a dead giveaway that the source used `On Error`, not `Try/Catch`.

The figure below summarises which VB accent maps to which runtime fingerprint, and what Glass shows you for each.

<figure class="my-8"><svg viewBox="0 0 680 232" role="img" aria-label="Five Visual Basic language features on the left each lower to a Microsoft.VisualBasic runtime helper in the middle, which Glass reconstructs into the readable C# on the right: Module becomes StandardModule static class, late binding becomes NewLateBinding.LateGet or dynamic, Option Compare becomes Operators.CompareString, On Error becomes ProjectData error handling, and implicit conversion becomes Conversions.ToX" style="width:100%;height:auto"><defs><style>.vb{fill:#eef4ff;stroke:#8eb4ff;stroke-width:1.5}.rt{fill:#fef9c3;stroke:#eab308;stroke-width:1.5}.cs{fill:#e6fffb;stroke:#2dd4bf;stroke-width:1.5}.ar{stroke:#94a3b8;stroke-width:1.5;fill:none}</style><marker id="h" markerWidth="8" markerHeight="8" refX="6" refY="3" orient="auto"><path d="M0 0l6 3-6 3z" fill="#94a3b8"/></marker></defs><text x="90" y="20" style="font:600 13px system-ui" fill="#1547e0" text-anchor="middle">VB feature</text><text x="340" y="20" style="font:600 13px system-ui" fill="#a16207" text-anchor="middle">runtime fingerprint</text><text x="590" y="20" style="font:600 13px system-ui" fill="#0f766e" text-anchor="middle">Glass shows C#</text><rect class="vb" x="10" y="32" width="160" height="30" rx="5"/><text x="20" y="51" style="font:12px system-ui" fill="#1e293b">Module</text><rect class="rt" x="250" y="32" width="180" height="30" rx="5"/><text x="260" y="51" style="font:11px system-ui" fill="#1e293b">StandardModuleAttribute</text><rect class="cs" x="500" y="32" width="170" height="30" rx="5"/><text x="510" y="51" style="font:11px system-ui" fill="#1e293b">static class</text><rect class="vb" x="10" y="72" width="160" height="30" rx="5"/><text x="20" y="91" style="font:12px system-ui" fill="#1e293b">late binding</text><rect class="rt" x="250" y="72" width="180" height="30" rx="5"/><text x="260" y="91" style="font:11px system-ui" fill="#1e293b">NewLateBinding.LateGet</text><rect class="cs" x="500" y="72" width="170" height="30" rx="5"/><text x="510" y="91" style="font:11px system-ui" fill="#1e293b">LateGet(...) / dynamic</text><rect class="vb" x="10" y="112" width="160" height="30" rx="5"/><text x="20" y="131" style="font:12px system-ui" fill="#1e293b">Option Compare</text><rect class="rt" x="250" y="112" width="180" height="30" rx="5"/><text x="260" y="131" style="font:11px system-ui" fill="#1e293b">Operators.CompareString</text><rect class="cs" x="500" y="112" width="170" height="30" rx="5"/><text x="510" y="131" style="font:11px system-ui" fill="#1e293b">CompareString(...) == 0</text><rect class="vb" x="10" y="152" width="160" height="30" rx="5"/><text x="20" y="171" style="font:12px system-ui" fill="#1e293b">On Error Resume Next</text><rect class="rt" x="250" y="152" width="180" height="30" rx="5"/><text x="260" y="171" style="font:11px system-ui" fill="#1e293b">ProjectData.SetProjectError</text><rect class="cs" x="500" y="152" width="170" height="30" rx="5"/><text x="510" y="171" style="font:11px system-ui" fill="#1e293b">try / catch skeleton</text><rect class="vb" x="10" y="192" width="160" height="30" rx="5"/><text x="20" y="211" style="font:12px system-ui" fill="#1e293b">implicit conversion</text><rect class="rt" x="250" y="192" width="180" height="30" rx="5"/><text x="260" y="211" style="font:11px system-ui" fill="#1e293b">Conversions.ToDouble</text><rect class="cs" x="500" y="192" width="170" height="30" rx="5"/><text x="510" y="211" style="font:11px system-ui" fill="#1e293b">Conversions.ToDouble(x)</text><path class="ar" d="M170 47 h76" marker-end="url(#h)"/><path class="ar" d="M430 47 h66" marker-end="url(#h)"/><path class="ar" d="M170 87 h76" marker-end="url(#h)"/><path class="ar" d="M430 87 h66" marker-end="url(#h)"/><path class="ar" d="M170 127 h76" marker-end="url(#h)"/><path class="ar" d="M430 127 h66" marker-end="url(#h)"/><path class="ar" d="M170 167 h76" marker-end="url(#h)"/><path class="ar" d="M430 167 h66" marker-end="url(#h)"/><path class="ar" d="M170 207 h76" marker-end="url(#h)"/><path class="ar" d="M430 207 h66" marker-end="url(#h)"/></svg></figure>

## Implicit conversions and the `My` namespace

Two smaller fingerprints round out the picture. First, VB converts implicitly where C# refuses. A VB expression that assigns a `String` to a `Double` compiles to `Conversions.ToDouble(s)` — the Visual Basic runtime's lenient parser — not a cast, and Glass shows that call so you know a *parse*, not a cast, was happening. Second, the `My` feature (`My.Application`, `My.Computer`, `My.Settings`) is pure compiler magic: the VB compiler generates a hidden `MyProject` type with nested `MyApplication`, `MyComputer` and settings classes, and rewrites every `My.` access into a property on it. In the decompiled C# you will find a generated `MyProject` class you never wrote — that is where `My` went.

## Reading it with Glass

Open the assembly in the Glass GUI and browse the tree; VB modules show up as the static classes they became, and the Visual Basic runtime reference is listed under the assembly's dependencies — itself a one-glance confirmation the binary was VB. To pull a single member from the command line:

```
glass decompile Legacy.Billing.dll --type Billing --member NetTotal
```

Add `--il` to see the raw IL beside the reconstructed C#, which is the fastest way to confirm what a `LateGet` or `CompareString` call was doing in the original:

```
glass decompile Legacy.Billing.dll --type Billing --member TitleOf --il
```

When you are ready to work on the whole thing — grep it, point an analyzer at it, or keep it as a permanent reference — export it to a buildable C# project:

```
glass export Legacy.Billing.dll --output ./Legacy.Billing.Source
```

You get a `.csproj`, reconstructed `.cs` files and any extracted resources. Opened in your editor, a fifteen-year-old VB component is now a C# project you can read, search and reason about — the first real step in either keeping it alive or porting it forward.

Glass is strictly static: it reads metadata, IL and resource blobs and reconstructs source, and never executes the assembly. That makes inspecting your own orphaned VB component, a licensed third-party library, or code you are analysing for interoperability both safe and sound — and Glass is completely free, with no licence, no seats and no sign-up.

