Serialization in Sandbox Solutions

If you have the pleasure of writing sandbox solutions, perhaps for Office365, you know that doing so involves a wide variety of creative workarounds. Serialization is one area where this creativity comes into play.

The problem with the XMLSerializer is that it creates and loads a serialization assembly on the fly. This doesn’t work in the sandbox. A good discussion and one solution to this problem is discussed here: Using the Application Setting Manager in Sandboxed Solutions.
An alternative approach is discussed here: Serialization Inside SandBox Solutions.

My alternative is to avoid XML Serialization altogether and use JSON via the JavaScriptSerializer class. This lovely class does not require an assembly and it works. Best of all, it creates a format that is easy to use in JavaScript which I tend to use heavily in SandBox solutions.

A terrific overview of this class can be found here on Rakki Muthukumar’s blog: ASP.NET – JSON – Serialization and Deserialization.

 

Author: Doug Ware