Error with Dynamic Serilizer

I was getting an exception trying to serialize a dynamic object… my problem was did not initialize as an expando object… so I found the correct way to do it but I think the exception could be better handled.

dynamic ProfileData = new { XYZ = "XYZ", DEF = "DEF"};
var clearJSON = DynamicJson.Serialize(ProfileData);

`ServiceStack.Text.JsonSerializer.SerializeToString<<>__AnonType0<string,string>>(<>__AnonType0<string,string>)’ is inaccessible due to its protection level

ok but this is just the underlying Exception being bubbled, we’re not going to be able to catch Exceptions from every scenario and wrap it in a friendlier Error message.

Also you can just use the normal JSON serializer to serialize an anonymous object, e.g:

var ProfileData = new { XYZ = "XYZ", DEF = "DEF"};
var clearJSON = ProfileData.ToJson();

Live demo on Gistlyn.