TryAddLineInfo() static private method

static private TryAddLineInfo ( System.Runtime.Serialization.XmlReaderDelegator reader, string errorMessage ) : string
reader System.Runtime.Serialization.XmlReaderDelegator
errorMessage string
return string
示例#1
0
        private object?InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, int declaredTypeID, Type declaredType, string?name, string?ns)
        {
            Debug.Assert(attributes != null);

            object?retObj = null;

            if (TryHandleNullOrRef(xmlReader, declaredType, name, ns, ref retObj))
            {
                return(retObj);
            }

            DataContract dataContract;
            string?      assemblyName = attributes.ClrAssembly;
            string?      typeName     = attributes.ClrType;

            if (assemblyName != null && typeName != null)
            {
                Assembly     assembly;
                Type         type;
                DataContract?tempDataContract = ResolveDataContractInSharedTypeMode(assemblyName, typeName, out assembly, out type);
                if (tempDataContract == null)
                {
                    if (assembly == null)
                    {
                        throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.AssemblyNotFound, assemblyName));
                    }

                    throw XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ClrTypeNotFound, assembly.FullName, typeName));
                }

                dataContract = tempDataContract;
                //Array covariance is not supported in XSD. If declared type is array, data is sent in format of base array
                if (declaredType != null && declaredType.IsArray)
                {
                    dataContract = (declaredTypeID < 0) ? GetDataContract(declaredType) : GetDataContract(declaredTypeID, declaredType.TypeHandle);
                }
            }
            else
            {
                if (assemblyName != null)
                {
                    throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.AttributeNotFound, Globals.SerializationNamespace, Globals.ClrTypeLocalName, xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName)));
                }
                else if (typeName != null)
                {
                    throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.AttributeNotFound, Globals.SerializationNamespace, Globals.ClrAssemblyLocalName, xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName)));
                }
                else if (declaredType == null)
                {
                    throw XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.AttributeNotFound, Globals.SerializationNamespace, Globals.ClrTypeLocalName, xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName)));
                }
                dataContract = (declaredTypeID < 0) ? GetDataContract(declaredType) : GetDataContract(declaredTypeID, declaredType.TypeHandle);
            }
            return(ReadDataContractValue(dataContract, xmlReader));
        }
示例#2
0
 private void ThrowConversionException(string value, string type)
 {
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.Format(SR.XmlInvalidConversion, value, type))));
 }
        internal static void ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, int memberIndex, int requiredIndex, XmlDictionaryString[] memberNames)
#endif
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (requiredIndex == memberNames.Length)
            {
                requiredIndex--;
            }
            for (int i = memberIndex + 1; i <= requiredIndex; i++)
            {
                if (stringBuilder.Length != 0)
                {
                    stringBuilder.Append(" | ");
                }
                stringBuilder.Append(memberNames[i].Value);
            }
            throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, SR.Format(SR.UnexpectedElementExpectingElements, xmlReader.NodeType, xmlReader.LocalName, xmlReader.NamespaceURI, stringBuilder.ToString()))));
        }
        protected object InternalDeserialize(XmlReaderDelegator reader, string name, string ns, ref DataContract dataContract)
        {
            object retObj = null;

            if (TryHandleNullOrRef(reader, dataContract.UnderlyingType, name, ns, ref retObj))
            {
                return(retObj);
            }

            bool knownTypesAddedInCurrentScope = false;

            if (dataContract.KnownDataContracts != null)
            {
                scopedKnownTypes.Push(dataContract.KnownDataContracts);
                knownTypesAddedInCurrentScope = true;
            }

            if (attributes.XsiTypeName != null)
            {
                dataContract = ResolveDataContractFromKnownTypes(attributes.XsiTypeName, attributes.XsiTypeNamespace, dataContract);
                if (dataContract == null)
                {
                    if (DataContractResolver == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotFoundOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName))));
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotResolvedOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName))));
                }
                knownTypesAddedInCurrentScope = ReplaceScopedKnownTypesTop(dataContract.KnownDataContracts, knownTypesAddedInCurrentScope);
            }

            if (knownTypesAddedInCurrentScope)
            {
                object obj = ReadDataContractValue(dataContract, reader);
                scopedKnownTypes.Pop();
                return(obj);
            }
            else
            {
                return(ReadDataContractValue(dataContract, reader));
            }
        }
示例#5
0
        protected object InternalDeserialize(XmlReaderDelegator reader, string name, string ns, Type declaredType, ref DataContract dataContract)
        {
            object retObj = null;

            if (this.TryHandleNullOrRef(reader, dataContract.UnderlyingType, name, ns, ref retObj))
            {
                return(retObj);
            }
            bool knownTypesAddedInCurrentScope = false;

            if (dataContract.KnownDataContracts != null)
            {
                this.scopedKnownTypes.Push(dataContract.KnownDataContracts);
                knownTypesAddedInCurrentScope = true;
            }
            if (this.attributes.XsiTypeName != null)
            {
                dataContract = base.ResolveDataContractFromKnownTypes(this.attributes.XsiTypeName, this.attributes.XsiTypeNamespace, dataContract, declaredType);
                if (dataContract == null)
                {
                    if (base.DataContractResolver == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, System.Runtime.Serialization.SR.GetString("DcTypeNotFoundOnDeserialize", new object[] { this.attributes.XsiTypeNamespace, this.attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName }))));
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, System.Runtime.Serialization.SR.GetString("DcTypeNotResolvedOnDeserialize", new object[] { this.attributes.XsiTypeNamespace, this.attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName }))));
                }
                knownTypesAddedInCurrentScope = this.ReplaceScopedKnownTypesTop(dataContract.KnownDataContracts, knownTypesAddedInCurrentScope);
            }
            if (dataContract.IsISerializable && (this.attributes.FactoryTypeName != null))
            {
                DataContract contract = base.ResolveDataContractFromKnownTypes(this.attributes.FactoryTypeName, this.attributes.FactoryTypeNamespace, dataContract, declaredType);
                if (contract != null)
                {
                    if (!contract.IsISerializable)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("FactoryTypeNotISerializable", new object[] { DataContract.GetClrTypeFullName(contract.UnderlyingType), DataContract.GetClrTypeFullName(dataContract.UnderlyingType) })));
                    }
                    dataContract = contract;
                    knownTypesAddedInCurrentScope = this.ReplaceScopedKnownTypesTop(dataContract.KnownDataContracts, knownTypesAddedInCurrentScope);
                }
                else if (DiagnosticUtility.ShouldTraceWarning)
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>(2);
                    dictionary["FactoryType"]       = this.attributes.FactoryTypeNamespace + ":" + this.attributes.FactoryTypeName;
                    dictionary["ISerializableType"] = dataContract.StableName.Namespace + ":" + dataContract.StableName.Name;
                    TraceUtility.Trace(TraceEventType.Warning, 0x30011, System.Runtime.Serialization.SR.GetString("TraceCodeFactoryTypeNotFound"), new DictionaryTraceRecord(dictionary));
                }
            }
            if (knownTypesAddedInCurrentScope)
            {
                object obj3 = this.ReadDataContractValue(dataContract, reader);
                this.scopedKnownTypes.Pop();
                return(obj3);
            }
            return(this.ReadDataContractValue(dataContract, reader));
        }
示例#6
0
        public static void ThrowRequiredMemberMissingException(XmlReaderDelegator xmlReader, int memberIndex, int requiredIndex, XmlDictionaryString[] memberNames)
        {
            StringBuilder builder = new StringBuilder();

            if (requiredIndex == memberNames.Length)
            {
                requiredIndex--;
            }
            for (int i = memberIndex + 1; i <= requiredIndex; i++)
            {
                if (builder.Length != 0)
                {
                    builder.Append(" | ");
                }
                builder.Append(memberNames[i].Value);
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, System.Runtime.Serialization.SR.GetString("UnexpectedElementExpectingElements", new object[] { xmlReader.NodeType, xmlReader.LocalName, xmlReader.NamespaceURI, builder.ToString() }))));
        }
示例#7
0
 private void ThrowConversionException(string value, string type)
 {
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(XmlObjectSerializer.TryAddLineInfo(this, System.Runtime.Serialization.SR.GetString("XmlInvalidConversion", new object[] { value, type }))));
 }
        private object InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, int declaredTypeID, Type declaredType, string name, string ns)
        {
            object       retObj = null;
            DataContract contract;

            if (base.TryHandleNullOrRef(xmlReader, declaredType, name, ns, ref retObj))
            {
                return(retObj);
            }
            string clrAssembly = base.attributes.ClrAssembly;
            string clrType     = base.attributes.ClrType;

            if ((clrAssembly != null) && (clrType != null))
            {
                Assembly assembly;
                Type     type;
                contract = this.ResolveDataContractInSharedTypeMode(clrAssembly, clrType, out assembly, out type);
                if (contract == null)
                {
                    if (assembly == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("AssemblyNotFound", new object[] { clrAssembly })));
                    }
                    if (type == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("ClrTypeNotFound", new object[] { assembly.FullName, clrType })));
                    }
                }
                if ((declaredType != null) && declaredType.IsArray)
                {
                    contract = (declaredTypeID < 0) ? base.GetDataContract(declaredType) : this.GetDataContract(declaredTypeID, declaredType.TypeHandle);
                }
            }
            else
            {
                if (clrAssembly != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, System.Runtime.Serialization.SR.GetString("AttributeNotFound", new object[] { "http://schemas.microsoft.com/2003/10/Serialization/", "Type", xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName }))));
                }
                if (clrType != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, System.Runtime.Serialization.SR.GetString("AttributeNotFound", new object[] { "http://schemas.microsoft.com/2003/10/Serialization/", "Assembly", xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName }))));
                }
                if (declaredType == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(xmlReader, System.Runtime.Serialization.SR.GetString("AttributeNotFound", new object[] { "http://schemas.microsoft.com/2003/10/Serialization/", "Type", xmlReader.NodeType, xmlReader.NamespaceURI, xmlReader.LocalName }))));
                }
                contract = (declaredTypeID < 0) ? base.GetDataContract(declaredType) : this.GetDataContract(declaredTypeID, declaredType.TypeHandle);
            }
            return(this.ReadDataContractValue(contract, xmlReader));
        }
        protected object?InternalDeserialize(XmlReaderDelegator reader, string?name, string?ns, Type declaredType, ref DataContract dataContract)
        {
            object?retObj = null;

            if (TryHandleNullOrRef(reader, dataContract.UnderlyingType, name, ns, ref retObj))
            {
                return(retObj);
            }

            bool knownTypesAddedInCurrentScope = false;

            if (dataContract.KnownDataContracts != null)
            {
                scopedKnownTypes.Push(dataContract.KnownDataContracts);
                knownTypesAddedInCurrentScope = true;
            }

            Debug.Assert(attributes != null);

            if (attributes.XsiTypeName != null)
            {
                DataContract?tempDataContract = ResolveDataContractFromKnownTypes(attributes.XsiTypeName, attributes.XsiTypeNamespace, dataContract, declaredType);
                if (tempDataContract == null)
                {
                    if (DataContractResolver == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotFoundOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName))));
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(XmlObjectSerializer.TryAddLineInfo(reader, SR.Format(SR.DcTypeNotResolvedOnDeserialize, attributes.XsiTypeNamespace, attributes.XsiTypeName, reader.NamespaceURI, reader.LocalName))));
                }
                dataContract = tempDataContract;
                knownTypesAddedInCurrentScope = ReplaceScopedKnownTypesTop(dataContract.KnownDataContracts, knownTypesAddedInCurrentScope);
            }

            if (dataContract.IsISerializable && attributes.FactoryTypeName != null)
            {
                DataContract?factoryDataContract = ResolveDataContractFromKnownTypes(attributes.FactoryTypeName, attributes.FactoryTypeNamespace, dataContract, declaredType);
                if (factoryDataContract != null)
                {
                    if (factoryDataContract.IsISerializable)
                    {
                        dataContract = factoryDataContract;
                        knownTypesAddedInCurrentScope = ReplaceScopedKnownTypesTop(dataContract.KnownDataContracts, knownTypesAddedInCurrentScope);
                    }
                    else
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.FactoryTypeNotISerializable, DataContract.GetClrTypeFullName(factoryDataContract.UnderlyingType), DataContract.GetClrTypeFullName(dataContract.UnderlyingType))));
                    }
                }
            }

            if (knownTypesAddedInCurrentScope)
            {
                object?obj = ReadDataContractValue(dataContract, reader);
                scopedKnownTypes.Pop();
                return(obj);
            }
            else
            {
                return(ReadDataContractValue(dataContract, reader));
            }
        }