另一个 {"<XXX xmlns=''> 不是预期的。"} 反序列化错误
Another {"<XXX xmlns=''> was not expected."} Deserializing Error
所以我知道有很多与此相关的问题,我已经仔细阅读了这些问题,但仍然无法解决我的这个问题实例。
内部异常:
{"<CostSchedule xmlns='urn:un:unece:uncefact:data:standard:CostSchedule:3'> was not expected."}
我的 XML 文档是这样开头的:
<urn:CostSchedule
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:urn="urn:un:unece:uncefact:data:standard:CostSchedule:3"
xmlns:urn1="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:8"
xsi:schemaLocation="urn:un:unece:uncefact:data:standard:CostSchedule:3 http://www.unece.org/fileadmin/DAM/uncefact/data/standard/CostSchedule_3p0.xsd"
xmlns="urn:un:unece:uncefact:data:standard:CostSchedule:3">
我正在尝试使用上述文档模式将其反序列化为 xsd.exe 定义的 class。 class 是这样开始的:
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:un:unece:uncefact:data:standard:CostSchedule:3"), _
System.Xml.Serialization.XmlRootAttribute([ElementName]:="CostSchedule", [Namespace]:="urn:un:unece:uncefact:data:standard:CostSchedule:3", IsNullable:=False)> _
Partial Public Class CostScheduleType
谁能指出我在这里遗漏了什么?在我看来,我似乎拥有 class 的所有必要序列化标签,但我似乎无法完成这项工作。
想通了。
反序列化器要求我明确说明我正在反序列化的对象类型。
ElementsLocal = New CostScheduleType
'This was ElementsLocal = New Object before
Dim ser As New XmlSerializer(ElementsLocal.GetType)
Using fs As FileStream = New FileStream(LocalFileURI, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Using objStreamReader As New XmlTextReader(fs)
'If ser.CanDeserialize(objStreamReader) Then ElementsLocal = ser.Deserialize(objStreamReader)
ElementsLocal = ser.Deserialize(objStreamReader)
所以我知道有很多与此相关的问题,我已经仔细阅读了这些问题,但仍然无法解决我的这个问题实例。
内部异常:
{"<CostSchedule xmlns='urn:un:unece:uncefact:data:standard:CostSchedule:3'> was not expected."}
我的 XML 文档是这样开头的:
<urn:CostSchedule
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:urn="urn:un:unece:uncefact:data:standard:CostSchedule:3"
xmlns:urn1="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:8"
xsi:schemaLocation="urn:un:unece:uncefact:data:standard:CostSchedule:3 http://www.unece.org/fileadmin/DAM/uncefact/data/standard/CostSchedule_3p0.xsd"
xmlns="urn:un:unece:uncefact:data:standard:CostSchedule:3">
我正在尝试使用上述文档模式将其反序列化为 xsd.exe 定义的 class。 class 是这样开始的:
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="urn:un:unece:uncefact:data:standard:CostSchedule:3"), _
System.Xml.Serialization.XmlRootAttribute([ElementName]:="CostSchedule", [Namespace]:="urn:un:unece:uncefact:data:standard:CostSchedule:3", IsNullable:=False)> _
Partial Public Class CostScheduleType
谁能指出我在这里遗漏了什么?在我看来,我似乎拥有 class 的所有必要序列化标签,但我似乎无法完成这项工作。
想通了。
反序列化器要求我明确说明我正在反序列化的对象类型。
ElementsLocal = New CostScheduleType
'This was ElementsLocal = New Object before
Dim ser As New XmlSerializer(ElementsLocal.GetType)
Using fs As FileStream = New FileStream(LocalFileURI, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Using objStreamReader As New XmlTextReader(fs)
'If ser.CanDeserialize(objStreamReader) Then ElementsLocal = ser.Deserialize(objStreamReader)
ElementsLocal = ser.Deserialize(objStreamReader)