/// <exception cref="XmlSerializationException"> /// An error occurred while deserializing the type. /// </exception> private Object Deserialize(XmlReader xmlReader, XmlDeserializationProvider xmlDeserializationProvider) { if (xmlReader == null) { throw new ArgumentNullException(); } if (xmlDeserializationProvider == null) { throw new ArgumentNullException(); } Object instance; if (!this.IsCustomSerialized) { try { instance = Activator.CreateInstance(this.TargetType); } catch (Exception exception) { var ex = new XmlSerializationException("The parameterless contructor of the type threw an exception. See inner exception for more details.", exception); ex.Data.Add("Type Name", this.TargetType.FullName); throw ex; } xmlDeserializationProvider.ReadAll(instance); } else { try { instance = Activator.CreateInstance(this.TargetType, xmlDeserializationProvider); } catch (Exception exception) { var ex = new XmlSerializationException("An error occurred while deserializing the type by its custom deserialization constructor. See inner exception for more details.", exception); ex.Data.Add("Type Name", this.TargetType.FullName); throw ex; } } if (xmlReader.NodeType == XmlNodeType.EndElement) { xmlReader.ReadEndElement(); } return(instance); }