Open any protected .NET assembly in a decompiler and the type names are already gone — a, b, c, meaningless. Yet the tree on the left still reads like a floor plan: Acme.Billing, Acme.Licensing, Acme.Core.Crypto. The names are obfuscated; the map is not. Anyone skimming that tree knows exactly where your license validation lives before they read a single instruction. Flattening namespaces removes that map — and it works because of a fact most engineers never have reason to learn: a .NET namespace is not a container. It is a string.
A namespace is not a node
In your source, namespace Acme.Billing { class InvoiceService { } } looks like it puts a class inside something. It does not. When the compiler emits metadata, there is no "namespace" record anywhere in the assembly — no namespace table, no parent node, nothing that owns the type. The TypeDef metadata table has one row per type, and each row carries two separate columns that both point into the string heap:
-
Name— the simple type name, e.g.InvoiceService. -
Namespace— the dotted namespace as a flat string, e.g.Acme.Billing.
That second column is the entire namespace. It is a per-type prefix, stored independently on every type, and the dots in it are just characters — the runtime never splits Acme.Billing into Acme and Billing. The hierarchy you see in a decompiler or in Solution Explorer is reconstructed by the tool, after the fact, by grouping TypeDef rows that happen to share a Namespace string. There is no tree in the file. There is a flat table of types, each wearing a label.
The nested-type subtlety
Here is the detail that makes flattening safe and surgical. A nested type — class Line declared inside InvoiceService — does not store its namespace. Its TypeDef row has an empty Namespace column. Its place in the world is expressed entirely through a different table, NestedClass, which records a link from the nested TypeDef to its enclosing TypeDef. The runtime reconstructs the nested type's full name as enclosing-full-name + + + nested-name — for example Acme.Billing.InvoiceService+Line. The namespace is inherited from the parent; the nested row itself says nothing about it.
That means flattening never has to touch nested types at all. They already have an empty Namespace. You only ever rewrite the Namespace column of top-level types — and when you clear a parent's namespace, every type nested inside it follows automatically, because the nested type's effective namespace was always just its parent's.
How Nebula flattens
Nebula.NET's renaming pass does exactly one thing for the namespace dimension, and it does it only on top-level types. After assigning a new opaque Name, it clears the Namespace column:
// For each renamable type, after choosing the new short name: t.Name = newName; if (t.DeclaringType is null) // top-level type only t.Namespace = string.Empty; // drop it into the global namespace // nested types (DeclaringType != null) are skipped: // their Namespace is already empty and follows the parent. DeclaringType is null is precisely the "is this a top-level type?" test. Nested types fall straight through, untouched, because their namespace lives in NestedClass, not on the row. The result is that every top-level type's Namespace becomes the empty string, and the whole assembly collapses into the global namespace. (If you prefer a single short bucket over the true global namespace — some tooling is happier with one non-empty namespace than with none — the same pass can instead write one short constant string into every top-level Namespace column. The mechanism is identical; only the value written differs.)
Consider what the reader loses. Before:
namespace Acme.Licensing { internal sealed class LicenseValidator { bool Check(string key){ /* ... */ } } } namespace Acme.Rendering { internal sealed class PdfExporter { void Export(Document d){ /* ... */ } } } After renaming and flattening, a decompiler reconstructs something like:
// global namespace — no Acme.Licensing, no Acme.Rendering internal sealed class a { bool a(string a){ /* ... */ } } internal sealed class b { void a(c a){ /* ... */ } } Type renaming alone would still have shown Acme.Licensing.a and Acme.Rendering.b — the attacker would not know what a does, but they would know which part of the system it belongs to, which is often enough to find the licensing code in seconds. Flattening erases that grouping. It composes with renaming rather than replacing it: renaming hides what each type is called, flattening hides how the types were organised.
For the mechanics of the Name rewrite itself, see choosing what to exclude from renaming in Nebula and what obfuscation breaks; this post is about the namespace column specifically. For a tour of the TypeDef, NestedClass, and string-heap tables themselves, see .NET metadata tables explained.
When it breaks — and what to keep
Flattening is a namespace-level case of the one universal obfuscation failure: something resolved a type by its full, string name at runtime. Clear the Namespace column and every such lookup now asks for a prefix that no longer exists. The specific casualties:
Type.GetType / Assembly.GetType by full name. The most direct break:
var t = Type.GetType("Acme.Licensing.LicenseValidator"); // → null after flattening var t2 = asm.GetType("Acme.Rendering.PdfExporter"); // → null The type is still in the assembly — it is just no longer called Acme.Licensing.LicenseValidator. Any plugin loader, factory, or config-driven instantiation that stores full type names as strings is affected.
Serialization that embeds assembly-qualified type names. BinaryFormatter-era payloads and JSON written with TypeNameHandling (Newtonsoft) or a polymorphic $type discriminator record the full type name on the wire. Flatten the namespace and previously serialized data can no longer bind back — the stored Acme.Billing.Invoice has no match. Round-tripping new data within one build is fine; reading old data, or data exchanged with an un-flattened peer, is not.
WPF / XAML. clr-namespace:Acme.Controls URIs, resource pack:// URIs that reference a namespace, and [assembly: XmlnsDefinition("...", "Acme.Controls")] all resolve CLR namespaces by their string. Flattening breaks every one of them. (XAML apps generally want the fuller treatment in obfuscating a WPF app.)
Anything else reflective over full names — DI that scans by namespace, test discovery, TypeNameHandling-style messaging — fails for the same reason.
The fix is the keep-list, applied to the namespace dimension: keep the full name (Name and Namespace) of any type that is resolved by its string. In nebula.config.json the renaming ruleset carries it, and a keep preserves the namespace along with the name:
{ "renaming": { "rules": [ { "pattern": "Acme.Plugins.Contracts.*", "action": "keep" }, { "pattern": "Acme.*", "action": "rename" } ] } } The better move, where you control the format, is to stop depending on the CLR type name at all: give serialized polymorphic types a stable discriminator you choose (not the .NET type name), register plugins by an explicit key rather than Type.GetType, and pin XAML namespaces so markup does not chase a clr-namespace. Each dependency you convert from "find this type by its full name" to "find this type by a name I own" is one you can flatten freely.
Prove the result the same way you prove any keep-list: open the protected assembly in Glass.NET, confirm the Namespace column is empty on everything that should be hidden and intact on everything a loader resolves by name, then run your integration suite against the flattened build — a serialization round-trip or a Type.GetType path surfaces a missing keep the instant it executes.
Takeaway
A namespace is a label, not a location — a per-type string in the TypeDef table's Namespace column, with nested types carrying an empty one and inheriting through NestedClass. Because it is only a string, Nebula.NET can erase your assembly's architectural map almost for free: clear the Namespace column on top-level types and the whole thing collapses into the global namespace, so renamed types no longer advertise which subsystem they came from. Keep the handful of full names that something resolves as a string, pin the rest to identities you control, and verify in a decompiler — then the map an attacker used to find your licensing code simply is not there.

