Skip to content
← All posts
· Delta1 Labs DecompilerGlass.NET.NETNuGet

Resolve references from a NuGet lockfile in Glass.NET

A decompiler is only as accurate as the references it can resolve. Point Glass.NET at your packages.lock.json and it loads the exact pinned package versions — so types, base classes and overloads resolve to what really restored, not a guess.

A decompiler earns your trust one reference at a time. Open an assembly that stands entirely on its own and the C# comes back clean. Open a real one — a service that leans on a dozen NuGet packages — and the quality of the reconstruction suddenly depends on something outside the file you opened: can the decompiler find the referenced assemblies, and the right versions of them?

When it can’t, the symptoms are familiar. A method returns JToken but the decompiler won’t expand the type or follow it to its base. An overload that differs only by a parameter type from a dependency resolves to // unresolved or the wrong candidate. Go-to-definition on an external symbol dead-ends. None of this is Glass guessing badly — it is Glass being honest that a reference it can’t load is a reference it can’t see through.

Glass.NET — the free, strictly static .NET decompiler — closes that gap by reading your packages.lock.json. The lockfile is the one artifact that says, authoritatively, which exact package versions your project restored. Hand it to Glass and every external reference resolves to the assembly that really shipped, not an approximation.

Why a name is not enough

A compiled assembly does not embed its dependencies. It embeds references to them. Two metadata tables carry the whole story:

  • AssemblyRef — one row per referenced assembly: its name, version, culture and public-key token.
  • TypeRef — one row per external type the code touches: the type’s name and namespace, and a pointer back to the AssemblyRef row that owns it.

That is enough to name a type at a call site. It is not enough to understand it. The base class, the interface list, the members, the constant values, the type forwarders — all of that lives in the referenced assembly’s own TypeDef metadata, which the referencing assembly never copies. So a decompiler with only the TypeRef can print Newtonsoft.Json.Linq.JObject but cannot know that JObject : JContainer : JToken, cannot list its members, and cannot resolve which op_Explicit conversion a cast selected. To see through the reference, it has to load the real assembly.

Consider this tiny method, compiled against Newtonsoft.Json:

using Newtonsoft.Json.Linq;

public static class Config
{
    public static string? ReadName(string json)
    {
        JObject root = JObject.Parse(json);
        return (string?)root["name"];
    }
}

Its IL is unambiguous about what it calls — every external member is a fully-qualified token:

.method public hidebysig static string ReadName(string json) cil managed
{
  .maxstack  2
  .locals init (class [Newtonsoft.Json]Newtonsoft.Json.Linq.JObject V_0)
  ldarg.0
  call       class [Newtonsoft.Json]Newtonsoft.Json.Linq.JObject
             [Newtonsoft.Json]Newtonsoft.Json.Linq.JObject::Parse(string)
  stloc.0
  ldloc.0
  ldstr      "name"
  callvirt   instance class [Newtonsoft.Json]Newtonsoft.Json.Linq.JToken
             [Newtonsoft.Json]Newtonsoft.Json.Linq.JToken::get_Item(object)
  call       string [Newtonsoft.Json]Newtonsoft.Json.Linq.JToken::
             op_Explicit(class [Newtonsoft.Json]Newtonsoft.Json.Linq.JToken)
  ret
}

Read the tokens and notice what is already in your assembly and what is not. The [Newtonsoft.Json] prefix is an AssemblyRef. get_Item is declared on JToken, but it is called through JObject — the IL only works because JObject inherits it, and that inheritance is recorded in Newtonsoft.Json, not here. The final op_Explicit is one of several explicit conversions on JToken; the token’s signature names the string-returning one, but to present it as a clean (string?) cast and to let you step into it, Glass needs the type’s definition. Without the assembly, Glass shows the shape it can prove from the tokens and marks the rest as external. With it, the cast, the inheritance and the member list all fill in.

The version trap: what the AssemblyRef says vs. what restored

You might think the AssemblyRef version solves the “which one” problem. It usually doesn’t. .NET libraries deliberately keep their assembly version stable across patch releases — Newtonsoft.Json has carried assembly version 13.0.0.0 across many 13.0.x NuGet releases — so the number baked into your AssemblyRef is not the package version that restored. Add a floating reference like <PackageReference Include="Newtonsoft.Json" Version="13.*" /> and the gap widens: the project compiled against whatever 13.0.x was current, the AssemblyRef still reads 13.0.0.0, and a probe that just looks for “a Newtonsoft.Json named 13.0.0.0” in your cache could bind any of several folders.

packages.lock.json is the artifact that removes the ambiguity. When RestorePackagesWithLockFile is on, NuGet writes the exact resolved version and a content hash for every package — direct and transitive:

{
  "version": 1,
  "dependencies": {
    "net8.0": {
      "Newtonsoft.Json": {
        "type": "Direct",
        "requested": "[13.*, )",
        "resolved": "13.0.3",
        "contentHash": "HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lAReUcg2cFTjaQ=="
      }
    }
  }
}

"resolved": "13.0.3" is the fact Glass wants. It maps straight to ~/.nuget/packages/newtonsoft.json/13.0.3/ in your local cache, so Glass loads that assembly — the one your build actually used — and not a near neighbour.

AssemblyRefNewtonsoft.Json 13.0.0.0cache: 13.0.1cache: 13.0.2cache: 13.0.3cache: 13.0.3-betawhich one?packages.lock.jsonresolved: 13.0.3exact match

Point Glass at the lockfile

From the CLI

Glass’s decompile command takes a lockfile and resolves every reference from it before it reconstructs a line:

glass decompile ./bin/Release/net8.0/Billing.dll \
      --lockfile ./packages.lock.json \
      --out ./recovered

Glass reads the lockfile, walks each resolved entry to the matching ~/.nuget/packages/<id>/<version>/lib/<tfm>/ folder, and loads those assemblies as the reference set. If a package carries its own lockfile-pinned transitive dependencies, those are in the file too, so the closure resolves in one pass — no network restore, no execution. Anything the lockfile can’t account for (a framework reference, a local project output next to the DLL) still resolves through Glass’s normal probing: the app directory, then the shared framework reference packs for the target TFM.

You can confirm what resolved before trusting the output. glass sbom reads the same inputs and prints the merged reference set with the exact versions Glass bound, so you can diff “what the lockfile said” against “what Glass loaded” and catch a gap — a package missing from the cache, say — rather than discovering it as an unresolved type three files deep.

In the UI

Open Billing.dll the usual way — drag it onto the window, or File ▸ Open Assembly. When a packages.lock.json sits in the project tree next to the binary, Glass notices it and offers Resolve references from lockfile in the assembly’s context menu (and in the notification strip). Accept it and the references node repopulates: entries that were italicised-and-unresolved turn solid, each tagged with the exact version from the lockfile. Now the payoff shows up everywhere the UI touches an external type:

  • Go to Definition (F12) on JObject opens the real type from 13.0.3, with its base chain and members, instead of stopping at an external stub.
  • The decompiled C# for ReadName presents a clean (string?)root["name"] because the indexer and the explicit conversion both resolved against the loaded type.
  • Find All References and the call hierarchy can follow calls across the boundary into the dependency, so “where does this value actually get validated?” is a few clicks rather than a guess.

If you ever need to know whether a specific detail came from the real assembly or from Glass inferring the shape from tokens alone, drop the member to the IL view. The tokens there are the ground truth the resolution builds on, and they read the same whether or not the reference loaded — which is exactly why they are the thing to fall back to.

When the lockfile earns its keep

  • Auditing a shipped third-party DLL. You have the vendor’s .dll and, next to it, the packages.lock.json from its build. Resolving against the lockfile gives you their exact dependency graph, so your reading of their code matches the assemblies they really linked — no drift from whatever happens to be in your cache.
  • Recovering a library whose source was lost. When you export a decompiled assembly to a buildable project, accurate references are what make the result actually compile. Resolving from the lockfile first means the recovered project points at the same package versions the original did.
  • Reproducing a version-specific bug. A defect that only appears with one patch of a dependency is invisible if your decompiler bound a different patch. Pinning to the lockfile’s resolved version makes the code you read the code that misbehaved.

The throughline is the same one that runs under every Glass workflow: it reads, it never runs. Resolving references from a lockfile is still pure static analysis — Glass reads the lockfile, reads the cached package metadata, and reconstructs C#. Nothing restores from the network, nothing executes. You just get a decompilation that is honest about the one thing a lone .dll can never tell you on its own: which dependency it was really built against.

Glass.NET is free — no licence, no seats, no sign-up. Point it at your own binaries, at dependencies you are entitled to inspect, or at code you are learning the compiler from, and let the lockfile make the references exact.

Try Nebula.NET

Harden your .NET code in minutes — start with the free edition.