When running JsonConvert.SerializeObject on an object {} is returned

shane_russoshane_russo Posts: 7 New member
edited December 13, 2018 9:02AM in SmartAssembly
I have obfuscated an assembly with Smart Assembly and when calling:

string json = JsonConvert.SerializeObject(drivers);

json ends up as "[{}]"

If I add [Serializable] to the class I end up with:
[{"dsh":[{},{},{},{}],"ds":[]},{"dsh":[{},{},{},{},{},{},{},{},{},{},{},{},{},{}],"ds":[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]}]

But still no values.

If I don't obfuscate the code then the json string is created correctly with the correct values.

What do I need to use to get the JsonConvert.SerializeObject(drivers); to correctly serialize?

I have added:
[Serializable SmartAssembly.Attributes.DoNotObfuscate SmartAssembly.Attributes.DoNotPrune SmartAssembly.Attributes.DoNotObfuscateType]

to the classes used in the drivers object without any success. 

Best Answer

  • shane_russoshane_russo Posts: 7 New member
    Accepted Answer
    Turns out that adding:

    [Serializable SmartAssembly.Attributes.DoNotPruneType]

    to the class fixes the problem.

    (Keep in mind that you have to reference the SmartAssembly.Attributes.dll in your project before you can add the command to your class)
Sign In or Register to comment.