I've had previous problems with obfuscating code with Dotfuscator. I seem to be cursed...I've found another one. Is no one else using this product to obfuscate CLR 2.0 code? This one is quite wicked. I spend several hours digging through before and after IL. (which is difficult when the purpose for obfuscation is to make it difficult to read) Here's the recipe for disaster:
- A generic method with the following characteristics:
- More than one type parameter.
- A return type composed of one or more of the method's type parameters other than the first one.
Some C# example signatures (Not useful or practical, just simple examples that show the problem):
static IEnumerable<TValues> FindDictionaryValues<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
static TValue FindAValueInADictionary<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
After obfuscation with dotfuscator (even with all obfuscation options disabled), those two signatures will look like:
static IEnumerable<TKey> FindDictionaryValues<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
static TKey FindAValueInADictionary<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
What happens is fairly simple. Any reference to the method's type parameters in the return type becomes a reference to the first type parameter (usually !!0 in the IL). What's more, this corruption also happens at the call site, which I didn't discover until I had written a regular expression to find and repair the corrupt signatures.
It is quite as if generics support was cobbled on as a hurried afterthought/sellingpoint rather than being properly integrated into their codebase. Their support for 2.0 is poor, even for "beta" status. However, Preemptive seems interested in fixing the issues. I'll update when I know more.
[UPDATE 10/06/2005] I wanted to let everyone know that PreEmptive is being very responsive to this issue. They've delivered a patch and I am currently evaluating it. So far, it appears to fix my issues, but we're working through a few other issues. Will update when I have more info.