Decompile an obfuscated .NET assembly and type names are gone, yet named tuple returns still read like documentation. The article explains why element names are not identifiers and how to strip them.
Key points
- Named tuple element names are never identifiers; the runtime type is ValueTuple<decimal, int> with Item1 and Item2.
- The compiler stores the names as a string array inside a TupleElementNamesAttribute on the return parameter.
- Renamers rewrite metadata identifier tables, not attribute blobs, which is why the names survive intact.
- The attribute appears on returns, parameters, fields and property types, but never on local variables.
- Nested and generic tuples flatten into one array with null placeholders, e.g. { null, "x", "y" } for List<(int x, int y)>.
- Switching the tuple to a readonly record struct turns every name into an identifier the renamer owns.
Why it matters
If you ship a closed-source library, this is one more thing your obfuscation pass does not cover, and the leak sits exactly where competitors read first: the public surface. Ordinary app developers are barely affected, but anyone exposing an internal boundary as public for a plugin host should audit decompiled output, not config files.
The concrete decision worth taking is the record struct swap: the names become real identifiers and the question disappears, at the price of a small source-level change for consumers. The flags shown here are Nebula-specific, so verify what your own obfuscator actually does.
Real-world use
- A shipped SDK library whose public API returns named tuples
- An internal boundary exposed as public only for a plugin host
- An application that is obfuscated and does not need to keep named access for consumers
This summary was generated by the agent from the original post on DEV Community: #csharp. The full text and all rights belong to its author and publisher. Go to original