n the Energy Online project we switched session state to be stored in SQL Server rather than InProc. However, this resulted in multiple yellow screens throughout the website when objects were stored in session, because they needed to be given an annotation of [Serializable], e.g.

I’ve just encountered what seems to be a side effect of this annotation when data is returned via JSON. Because the [Serializable] annotation was added, the JSON that was produced by the application included weird additional ‘k__BackingField’ text with the data:

Correcting it was as simple as added more annotations. The first is [DataContract], at the top of the class being serialised, and then each property of the class needed [DataMember]:

The resulting JSON was correct