Obfuscation and LINQ
Friday August 21st 2009On a .NET project I’m working on at the moment I stumbled across a problem yesterday when I started using LINQ to SQL as the ORM. It threw me at first, but once I realised what was going on it was simple to fix, but something to be aware of none the less.
The problem basically comes from obfuscating the assembly, in particular the LINQ classes generated by the LINQ Designer, which when you think about it makes perfect sense. If you obfuscate the table names in the LINQ generated class, how is the code going to know what table to connect to on the SQL database?
The simple solution is to exclude the LINQ generated classes from obfuscation. For me I use the excellent {smartassembly} so this is pretty easy, by just checking it in the {sa} interface. Alternatively you could use the custom attribute <DoNotObfuscate()> _ at the top of the class to tell {sa} to ignore it.