Obfuscation of Serializable type

Andy_LAndy_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>&nbsp;&nbsp;&nbsp; public MyEnum field1;</div><div><br></div><div>&nbsp;&nbsp;&nbsp; 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.


Sign In or Register to comment.