/// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.Deserialize5"]/*' /> public object Deserialize(XmlReader xmlReader, string encodingStyle, XmlDeserializationEvents events) { events.sender = this; try { if (_primitiveType != null) { if (encodingStyle != null && encodingStyle.Length > 0) { throw new InvalidOperationException(string.Format(ResXml.XmlInvalidEncodingNotEncoded1, encodingStyle)); } return(DeserializePrimitive(xmlReader, events)); } else if (_tempAssembly == null || _typedSerializer) { XmlSerializationReader reader = CreateReader(); reader.Init(xmlReader, events, encodingStyle, _tempAssembly); try { return(Deserialize(reader)); } finally { reader.Dispose(); } } else { return(_tempAssembly.InvokeReader(_mapping, xmlReader, events, encodingStyle)); } } catch (Exception e) { if (/*e is ThreadAbortException || e is StackOverflowException ||*/ e is OutOfMemoryException) { throw; } if (e is TargetInvocationException) { e = e.InnerException; } if (xmlReader is IXmlLineInfo) { IXmlLineInfo lineInfo = (IXmlLineInfo)xmlReader; throw new InvalidOperationException(string.Format(ResXml.XmlSerializeErrorDetails, lineInfo.LineNumber.ToString(), lineInfo.LinePosition.ToString()), e); } else { throw new InvalidOperationException(ResXml.XmlSerializeError, e); } } }
internal object InvokeReader(XmlMapping mapping, XmlReader xmlReader, XmlDeserializationEvents events, string encodingStyle) { XmlSerializationReader reader = null; try { encodingStyle = ValidateEncodingStyle(encodingStyle, mapping.Key); reader = Contract.Reader; reader.Init(xmlReader, events, encodingStyle, this); if (_methods[mapping.Key].readMethod == null) { if (_readerMethods == null) { _readerMethods = Contract.ReadMethods; } string methodName = (string)_readerMethods[mapping.Key]; if (methodName == null) { throw new InvalidOperationException(string.Format(ResXml.XmlNotSerializable, mapping.Accessor.Name)); } _methods[mapping.Key].readMethod = GetMethodFromType(reader.GetType(), methodName, _pregeneratedAssmbly ? _assembly : null); } return(_methods[mapping.Key].readMethod.Invoke(reader, s_emptyObjectArray)); } catch (SecurityException e) { throw new InvalidOperationException(ResXml.XmlNoPartialTrust, e); } finally { if (reader != null) { reader.Dispose(); } } }