The perils of Obfuscating your code

Suppose you have an enum type.

    internal enum SomeEnum       
{
SomeVeryDescriptiveName = 5
}

For some reason you want to use the name of the enum field as a string and not its value.
you can write:

Console.WriteLine(SomeEnum.SomeVeryDescriptiveName);

The output will be:
“SomeVeryDescriptiveName”
This is exactly what you wanted and every thing works fine.

But when you build the release version it doesn’t work.
So you debug it and of course under debug it works fine again.
Then you pull the heavy guns like the giants who walked on this earth long time ago taught you. Logging.
And than you find it:
When we build in release mode the assembly is obfuscated. This means that all internal and private names are mangled.
Since the enum is internal SomeEnum.SomeVeryDescriptiveName will become something like:
z.k and the output will be:
“k”
Thou shall not use strings!

TOP