ProdSens.live

Tuesday, 1 December 2026Eight desks, updated through the day

How .NET Namespace Flattening Changes Obfuscation and Runtime Lookups

Namespace flattening in .NET changes metadata rather than creating a new hierarchy, helping obscure type organization but putting string-based lookups, serialization and XAML references at risk.

How .NET Namespace Flattening Changes Obfuscation and Runtime Lookups — illustration

Key takeaways

  • .NET stores a type’s dotted namespace as one string in the TypeDef metadata table, not as a runtime hierarchy.

  • Flattening targets top-level types, identified by a null DeclaringType, and can move them into the global namespace.

  • Reflection, plugin loading, serialized type names and WPF/XAML namespace references may stop resolving after the change.

  • Teams can preserve names for required types, use application-controlled identifiers and test the flattened assembly in Glass.NET.

In .NET, a namespace is not a hierarchy stored in assembly metadata. It is a string attached to each type, which means an obfuscator can hide the original organization by changing those strings without rebuilding a namespace tree.

The relevant metadata is the TypeDef table. Each row describes one type and includes separate Name and Namespace fields. Both values refer to entries in the string heap. The namespace field holds the complete dotted value as one string; the runtime does not divide it into parent and child components.

Decompiler views and tools such as Solution Explorer can still display a tree because they group types whose Namespace values match. That presentation is reconstructed from the metadata rather than representing a hierarchy that the runtime stores directly.

What flattening changes

A nested type is handled differently. Its namespace field is empty, and the NestedClass table connects it to its enclosing type. Its effective namespace comes from that enclosing type, so a flattening pass should not rewrite nested types.

For top-level types, the operation identifies entries whose DeclaringType is null and replaces their namespace value with string.Empty. The result is that all top-level types appear in the global namespace. A short shared constant can also be written to those fields instead of using the empty value, although the source notes that some tooling may prefer that arrangement.

Namespace flattening can be combined with type renaming. Renaming obscures the type names themselves; changing namespace values obscures the original grouping of those types.

Where compatibility can break

The main risk is code that resolves types from their full string names. Clearing the namespace can affect Type.GetType, Assembly.GetType, string-based plugin loaders, factories, configuration-driven construction and other reflection paths that depend on those names.

Serialized data can also be affected when it embeds assembly-qualified type names. The source specifically identifies BinaryFormatter-era payloads and Newtonsoft TypeNameHandling or polymorphic $type discriminators as formats that may no longer bind data written with the former namespaces.

WPF and XAML references present another compatibility surface. Values such as clr-namespace:Acme.Controls, resource pack:// URIs that refer to namespaces and XmlnsDefinition declarations resolve CLR namespaces as strings, so flattening can break those references.

Safer deployment checks

Types that must be resolved by name should retain their original name and namespace through an obfuscator keep rule, such as one covering Acme.Plugins.Contracts.*. A longer-term design is to replace CLR-name lookup with application-owned identifiers: stable serialization discriminators, explicit plugin keys and pinned XAML namespaces are examples given by the source.

Before release, teams can inspect the resulting Namespace values in Glass.NET and run integration tests against the flattened assembly. That combination checks both the metadata transformation and the application paths most likely to depend on the old names.

Why it matters for your role

Pick the building you work in.

For software engineers

Engineers need to inventory every path that converts a full CLR type name into a runtime type, including reflection, plugins, factories and configuration-driven instantiation. Namespace flattening can be useful alongside renaming, but only when those dependencies are protected or replaced.

For QA engineers

Integration tests should run against the transformed assembly rather than only the unobfuscated build. Coverage should include serialized payload binding and WPF/XAML references where those mechanisms are used.

Based on reporting by DEV Community (source article).

Written with AI assistance and reviewed under our editorial standards. Spotted an error? Tell the desk.

Comments

Join the discussion

Your email address will not be published. Required fields are marked *

Follow the city on Telegram

Every new story from all eight desks, as it lands. No inbox, no sign-up form, just open the channel and read.

@prodsens

Product, project, software, QA, AI, analytics, marketing and planning news in one feed.

Open in Telegram (opens in a new tab)