CreateSerializationExceptionWithReaderDetails() static private method

static private CreateSerializationExceptionWithReaderDetails ( string errorMessage, System.Runtime.Serialization.XmlReaderDelegator reader ) : Exception
errorMessage string
reader System.Runtime.Serialization.XmlReaderDelegator
return System.Exception
        internal override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName, DataContractResolver dataContractResolver)
        {
            if (MaxItemsInObjectGraph == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph)));
            }

            if (dataContractResolver == null)
            {
                dataContractResolver = this.DataContractResolver;
            }

#if NET_NATIVE
            // Give the root contract a chance to initialize or pre-verify the read
            RootContract.PrepareToRead(xmlReader);
#endif
            if (verifyObjectName)
            {
                if (!InternalIsStartObject(xmlReader))
                {
                    XmlDictionaryString expectedName;
                    XmlDictionaryString expectedNs;
                    if (_rootName == null)
                    {
                        expectedName = RootContract.TopLevelElementName;
                        expectedNs   = RootContract.TopLevelElementNamespace;
                    }
                    else
                    {
                        expectedName = _rootName;
                        expectedNs   = _rootNamespace;
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElement, expectedNs, expectedName), xmlReader));
                }
            }
            else if (!IsStartElement(xmlReader))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingElementAtDeserialize, XmlNodeType.Element), xmlReader));
            }

            DataContract contract = RootContract;
            if (contract.IsPrimitive && object.ReferenceEquals(contract.UnderlyingType, _rootType) /*handle Nullable<T> differently*/)
            {
                return(contract.ReadXmlValue(xmlReader, null));
            }

            if (IsRootXmlAny(_rootName, contract))
            {
                return(XmlObjectSerializerReadContext.ReadRootIXmlSerializable(xmlReader, contract as XmlDataContract, false /*isMemberType*/));
            }

            XmlObjectSerializerReadContext context = XmlObjectSerializerReadContext.CreateContext(this, contract, dataContractResolver);

            return(context.InternalDeserialize(xmlReader, _rootType, contract, null, null));
        }
 internal override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
 {
     if (this.MaxItemsInObjectGraph == 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("ExceededMaxItemsQuota", new object[] { this.MaxItemsInObjectGraph })));
     }
     if (!base.IsStartElement(xmlReader))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(System.Runtime.Serialization.SR.GetString("ExpectingElementAtDeserialize", new object[] { XmlNodeType.Element }), xmlReader));
     }
     return(XmlObjectSerializerReadContext.CreateContext(this).InternalDeserialize(xmlReader, null, null, null));
 }
        internal override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName)
        {
            if (MaxItemsInObjectGraph == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph)));
            }

            // verifyObjectName has no effect in SharedType mode
            if (!IsStartElement(xmlReader))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.GetString(SR.ExpectingElementAtDeserialize, XmlNodeType.Element), xmlReader));
            }

            XmlObjectSerializerReadContext context = XmlObjectSerializerReadContext.CreateContext(this);

            return(context.InternalDeserialize(xmlReader, null, null, null));
        }
        internal override object InternalReadObject(XmlReaderDelegator xmlReader, bool verifyObjectName, System.Runtime.Serialization.DataContractResolver dataContractResolver)
        {
            if (this.MaxItemsInObjectGraph == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("ExceededMaxItemsQuota", new object[] { this.MaxItemsInObjectGraph })));
            }
            if (dataContractResolver == null)
            {
                dataContractResolver = this.DataContractResolver;
            }
            if (verifyObjectName)
            {
                if (!this.InternalIsStartObject(xmlReader))
                {
                    XmlDictionaryString topLevelElementName;
                    XmlDictionaryString topLevelElementNamespace;
                    if (this.rootName == null)
                    {
                        topLevelElementName      = this.RootContract.TopLevelElementName;
                        topLevelElementNamespace = this.RootContract.TopLevelElementNamespace;
                    }
                    else
                    {
                        topLevelElementName      = this.rootName;
                        topLevelElementNamespace = this.rootNamespace;
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(System.Runtime.Serialization.SR.GetString("ExpectingElement", new object[] { topLevelElementNamespace, topLevelElementName }), xmlReader));
                }
            }
            else if (!base.IsStartElement(xmlReader))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(System.Runtime.Serialization.SR.GetString("ExpectingElementAtDeserialize", new object[] { XmlNodeType.Element }), xmlReader));
            }
            DataContract rootContract = this.RootContract;

            if (rootContract.IsPrimitive && object.ReferenceEquals(rootContract.UnderlyingType, this.rootType))
            {
                return(rootContract.ReadXmlValue(xmlReader, null));
            }
            if (base.IsRootXmlAny(this.rootName, rootContract))
            {
                return(XmlObjectSerializerReadContext.ReadRootIXmlSerializable(xmlReader, rootContract as XmlDataContract, false));
            }
            return(XmlObjectSerializerReadContext.CreateContext(this, rootContract, dataContractResolver).InternalDeserialize(xmlReader, this.rootType, rootContract, null, null));
        }
        internal static Exception CreateUnexpectedStateException(XmlNodeType expectedState, XmlReaderDelegator xmlReader)
#endif
        {
            return(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(SR.Format(SR.ExpectingState, expectedState), xmlReader));
        }
示例#6
0
 public static Exception CreateUnexpectedStateException(XmlNodeType expectedState, XmlReaderDelegator xmlReader)
 {
     return(XmlObjectSerializer.CreateSerializationExceptionWithReaderDetails(System.Runtime.Serialization.SR.GetString("ExpectingState", new object[] { expectedState }), xmlReader));
 }