public static object Deserialize(XDocument stateData, string keyType)
        {
            try
            {
                return(DeserializeInternal(stateData, keyType));
            }
            catch (Exception)
            {
                var reader = stateData.CreateReader();
                reader.MoveToContent();
                var patchedText = SerializationPatcher.Apply(reader.ReadOuterXml(), new RemoveBackingFieldPatch(keyType));

                return(DeserializeInternal(XDocument.Parse(patchedText), keyType));
            }
        }
        public IMessage[] Deserialize(Stream stream)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(stream);

            try
            {
                return(Deserialize(xmlDocument));
            }
            catch (Exception)
            {
                var patchedText        = SerializationPatcher.Apply(xmlDocument.InnerXml);
                var patchedXmlDocument = new XmlDocument();
                patchedXmlDocument.LoadXml(patchedText);
                return(Deserialize(patchedXmlDocument));
            }
        }