Obfuscation of Serializable type
Andy_L
Posts: 4 New member
I've found an issue with SmartAssembly's treatment of serializable types. If I have code like this in a .EXE assembly:
<div>public enum MyEnum { value1, value2 }</div><div><br></div><div>public enum MyOtherEnum { otherValue3, otherValue4 }</div><div><br></div><div><br></div><div>[Serializable]</div><div><br></div><div>public class MySerializableType</div><div><br></div><div>{</div><div><br></div><div> public MyEnum field1;</div><div><br></div><div> public MyOtherEnum? field2;</div><div><br></div><div>}</div>
SmartAssembly avoids obfuscating Serializable classes, to prevent problems with deserialization. But it doesn't seem to follow the object graph properly. It detects that MyEnum is used in a Serializable type, and so correctly avoids obfuscating the values of MyEnum. But because MyOtherEnum is used indirectly as a Nullable<MyOtherEnum>, SmartAssembly doesn't pick it up as being used in the Serializable type, obfuscates it, and now I can't deserialize any instance of MySerializableType that was serialized in an unobfuscated (or differently obfuscated) build.
I have to explicitly mark MyOtherEnum as Serializable to prevent it being obfuscated (normally unnecessary because enums are implicitly serializable).
I think SmartAssembly needs to consider generic type parameters when working out what's part of a Serializable class. If the class contains a Nullable<Something> or a List<Something>, then the "Something" is going to need to remain unobfuscated if you want to avoid problems with serialization.
Tagged:
Answers
Automatically turning off everything that's correlated to serializable types in an application may introduce disabling obfuscation for a lot of its functionality. Thus the user should be informed when it happens AND/OR we should introduce a SmartAssembly serialization mechanism that will be able to obfuscate and serialize things properly (it may be just some interface-ish API).
We'll discuss it and see how to proceed.