public BinaryMessageSerializer()
{
var surrogateSelector = new SurrogateSelector();
surrogateSelector.AddSurrogate(typeof(XDocument), new StreamingContext(StreamingContextStates.All), new XContainerSurrogate());
surrogateSelector.AddSurrogate(typeof(XElement), new StreamingContext(StreamingContextStates.All), new XElementSurrogate());
binaryFormatter.SurrogateSelector = surrogateSelector;
}