Recovering the strongly-typed Resources designer with Glass.NET
A `Resources.Designer.cs` is machine-generated glue: a lazy `ResourceManager`, a culture field, and one typed property per `.resx` key that just calls `GetString`. None of that keyword-magic survives compilation — it is plain IL. Glass.NET reads the attribute fingerprint and the `GetString` shape back into the familiar designer class. Here is the full source → IL → reconstructed C# round-trip.
Open almost any localized .NET application and you will find a file nobody wrote by hand: Resources.Designer.cs. Visual Studio’s ResXFileCodeGenerator produces it from a .resx file, and it gives you Resources.Greeting instead of a stringly-typed resourceManager.GetString("Greeting") scattered through your code. It is pure convenience glue — a lazily-initialized ResourceManager, a culture field, and one property per resource key.
When you decompile an assembly, that generated class is just another type in the metadata. There is no marker that says “this was designer-generated,” no .resx embedded as source. But the shape is extremely regular, and that regularity is exactly what Glass.NET, the free .NET decompiler, keys on to hand you back a readable designer class instead of a pile of GetString calls. This post walks one resource accessor from source to IL and back, and shows how Glass recovers both the typed class and the resource keys behind it.
The source
Start with a two-entry .resx. Conceptually it is just a key/value table:
| Name | Value |
|---|---|
Greeting | Hello, {0}! |
Farewell | Goodbye. |
The generator turns that into a class. Here is the relevant core of what ResXFileCodeGenerator emits (trimmed to two members, fully-qualified names collapsed for readability):
[System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[System.Diagnostics.DebuggerNonUserCodeAttribute]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
internal class Resources
{
private static System.Resources.ResourceManager resourceMan;
private static System.Globalization.CultureInfo resourceCulture;
internal static System.Resources.ResourceManager ResourceManager
{
get
{
if (object.ReferenceEquals(resourceMan, null))
{
var temp = new System.Resources.ResourceManager(
"MyApp.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
internal static System.Globalization.CultureInfo Culture
{
get { return resourceCulture; }
set { resourceCulture = value; }
}
internal static string Greeting =>
ResourceManager.GetString("Greeting", resourceCulture);
}
Two parts matter for reconstruction: the lazy ResourceManager getter (a null check that constructs the manager once and caches it) and the typed property (Greeting), which is nothing but a forwarded GetString keyed by the property’s own name.
What the compiler emits
The typed property is the interesting one, because it is the piece that repeats once per key and the piece a reader most wants collapsed. Here is get_Greeting as ildasm/Glass shows it:
.method assembly hidebysig specialname static
string get_Greeting () cil managed
{
.maxstack 8
IL_0000: call class [System.Resources]System.Resources.ResourceManager Resources::get_ResourceManager()
IL_0005: ldstr "Greeting"
IL_000a: ldsfld class [System.Globalization]System.Globalization.CultureInfo Resources::resourceCulture
IL_000f: callvirt instance string [System.Resources]System.Resources.ResourceManager::GetString(string, class [System.Globalization]System.Globalization.CultureInfo)
IL_0014: ret
}
Read it straight through: call the ResourceManager property, push the literal key "Greeting", push the static resourceCulture field, call GetString(string, CultureInfo), return the result. The key string in the ldstr is identical to the property name — that equality is the heart of the fingerprint.
The lazy getter lowers to the familiar check-and-cache:
.method assembly hidebysig specialname static
class [System.Resources]System.Resources.ResourceManager get_ResourceManager () cil managed
{
.maxstack 8
.locals init (class [System.Resources]System.Resources.ResourceManager V_0)
IL_0000: ldsfld class ...ResourceManager Resources::resourceMan
IL_0005: ldnull
IL_0006: call bool [System.Runtime]System.Object::ReferenceEquals(object, object)
IL_000b: brfalse.s IL_0021
IL_000d: ldstr "MyApp.Resources"
IL_0012: ldtoken Resources
IL_0017: call class [System.Runtime]System.Type System.Type::GetTypeFromHandle(valuetype ...RuntimeTypeHandle)
IL_001c: callvirt instance class [System.Runtime]System.Reflection.Assembly System.Type::get_Assembly()
IL_0021: ... newobj ResourceManager(string, Assembly) ; stsfld resourceMan
IL_... : ldsfld resourceMan
IL_... : ret
}
The newobj carries the base name of the resource set — "MyApp.Resources" — which tells you exactly which embedded .resources stream holds the values. Hold onto that; it is how Glass finds the keys.
The fingerprint Glass keys on
Glass does not guess. A generated resources class carries a precise, machine-applied signature, and Glass matches on the combination rather than any single clue:
Stated precisely, the recognition rule is: a type carrying GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", …), holding a static ResourceManager field with a lazy caching getter and a static CultureInfo field, whose remaining instance-less properties each consist of a single GetString call whose literal key equals the property’s own name. When that holds, Glass labels the type a resources accessor and renders the getters in their idiomatic one-line form rather than as expanded GetString bodies.
What Glass reconstructs
Point the decompiler at the assembly:
glass decompile MyApp.dll --type Resources
Glass produces the designer class essentially as the generator wrote it — attributes intact, the lazy ResourceManager getter restored to its canonical form, and each key as a tidy expression-bodied property:
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan is null)
resourceMan = new ResourceManager("MyApp.Resources", typeof(Resources).Assembly);
return resourceMan;
}
}
internal static CultureInfo Culture
{
get => resourceCulture;
set => resourceCulture = value;
}
internal static string Greeting => ResourceManager.GetString("Greeting", resourceCulture);
internal static string Farewell => ResourceManager.GetString("Farewell", resourceCulture);
}
That is the original designer file, down to the resource base name and the per-key property names. The ReferenceEquals(resourceMan, null) call that the generator emits is rendered as the equivalent is null; both are the same test, and Glass picks the form a reader expects.
Recovering the values, not just the keys
The class tells you the keys; the values live in an embedded .resources stream named after the base name — MyApp.Resources.resources. Glass can read that stream directly and show the key/value table, which is what you actually want when you are trying to understand a localized build or recover copy from an app whose .resx source was lost:
glass resources MyApp.dll --set MyApp.Resources
Key Type Value
--------- -------- -----------------
Greeting string "Hello, {0}!"
Farewell string "Goodbye."
Pair that with the reconstructed class and you have the whole picture: the typed API surface and the strings behind it. If the assembly ships satellite assemblies for other cultures (fr/MyApp.resources.dll, de/MyApp.resources.dll), run the same command against each to diff the translations — a quick way to audit which keys a localizer actually filled in.
When the pattern does not hold
The match degrades honestly. If a property that looks like an accessor does something a plain GetString forward cannot express — returns a byte[] via GetObject for an embedded image, applies formatting, or reads a key whose name differs from the property — Glass does not pretend it is the simple string shape. Image and audio resources (which the builder emits as GetObject/Bitmap casts) are reconstructed as exactly that, and any property whose literal key diverges from its name is shown with the real key preserved. You never get a reconstruction that would compile to different behavior than the metadata describes.
Why this matters for reading real code
A decompiled resources class, left un-recognized, is one of the noisiest things in an assembly: dozens of near-identical getters, each with its own GetString body, burying the handful of facts you came for — which keys exist, and what do they say. Collapsing them back to the designer form turns that noise into a table you can scan in seconds, and surfacing the embedded .resources stream gives you the values without ever leaving the tool.
Glass is a free, static-only decompiler built for exactly this kind of understanding — your own assemblies, your dependencies, a localized build whose source drifted away from the binary. It reads IL and embedded metadata to C#; it does not run, patch, or modify anything. Point it at a DLL in the Visual-Studio-native UI, the CLI, or over MCP, and the designer class — and the strings it wraps — come back the way you remember writing them.
Try Nebula.NET
Harden your .NET code in minutes — start with the free edition.