-1

The following Code throws an XML deserialisation error (20,2) and i don't know why. Is there somethign special with XmlSerialiser to know for deserialisation of DataSets?

Dim strStringReader As StringReader = New StringReader(strValue)
Dim oXS As XmlSerializer = New XmlSerializer(strObjectType)
Deserialize = oXS.Deserialize(strStringReader)

this is the xml (available in a string strValue):

<?xml version='1.0' encoding='utf-16'?>
<DataTable>
<xs:schema id='DocumentElement' xmlns='' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
  <xs:element name='DocumentElement' msdata:IsDataSet='true' msdata:UseCurrentLocale='true'>
    <xs:complexType>
      <xs:choice minOccurs='0' maxOccurs='unbounded'>
        <xs:element name='tblCategoryLanguageElements'>
          <xs:complexType>
            <xs:sequence>
              <xs:element name='_LE_LanguageID' type='xs:string' minOccurs='0' />
              <xs:element name='_LE_FieldID' type='xs:string' minOccurs='0' />
              <xs:element name='_LE_Value' type='xs:string' minOccurs='0' />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' xmlns:diffgr='urn:schemas-microsoft-com:xml-diffgram-v1'>
  <DocumentElement>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements1' msdata:rowOrder='0' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>1</_LE_FieldID>
      <_LE_Value>Components</_LE_Value>
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements2' msdata:rowOrder='1' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>2</_LE_FieldID>
      <_LE_Value>Imported by OT2KARTRISSync</_LE_Value>
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements3' msdata:rowOrder='2' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>3</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements4' msdata:rowOrder='3' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>4</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements5' msdata:rowOrder='4' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>5</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
    <tblCategoryLanguageElements diffgr:id='tblCategoryLanguageElements6' msdata:rowOrder='5' diffgr:hasChanges='inserted'>
      <_LE_LanguageID>1</_LE_LanguageID>
      <_LE_FieldID>8</_LE_FieldID>
      <_LE_Value />
    </tblCategoryLanguageElements>
  </DocumentElement>
</diffgr:diffgram>
</DataTable>

The Position (20,2) is this:

<diffgr:diffgram xmlns:msdata='urn:sche...

Any help appreciated !!

MadMaxApp

MadMaxAPP
  • 1,035
  • 2
  • 16
  • 39

1 Answers1

2

For DataSets and DataTables, there are special methods to write and read Xml. DataSets and DataTables can be serialized in a number of ways, so there are some overloads. From the XML you show in your question, I suspect that the caller sends a DiffGram of a DataTable to your webservice, a special format that contains the changes that have been made to the data in the DataSet or DataTable.
You can read the DiffGram using one of the ReadXml overloads.

Markus
  • 20,838
  • 4
  • 31
  • 55
  • Thx. I serialize the dataset in c# to a DiffGram cause the VB WebService want's it that way. Also the schema at the beginning is needed for the WebService to work properly in deserializing a dataset. What i not understand is, why the VB XmlSerializer throws an XML deserializsation error on row 20 column 2 ? The XML looks fine and is generated with writeXml vom dataSet. – MadMaxAPP Nov 08 '13 at 12:59
  • The format that is used by XmlSerializer is different from the one that DataSet.WriteXml uses. I just checked it, DataSet.ReadXml reads your XML into a DataSet without a problem. I used an untyped DataSet and was able to have a look at the tblCategoryLanguageElements table. – Markus Nov 08 '13 at 14:04
  • That means, that i need to serialize the DataSet in C# with a different serializer? I can not change the vb code at the server side. – MadMaxAPP Nov 11 '13 at 08:08
  • If you cannot change the server side, I hope you can at least change the C# client. If the server can't handle a serialized DataSet, do not send one. Instead, send data in an XML format that complies with the format the server expects. Maybe you can access a DLL that contains the object definitions that the server uses or you need to build a class structure that serializes to the XML the server expects. – Markus Nov 11 '13 at 08:21
  • I serialise the dataset with xmlserialiser in my c# code on the client side now and it works!! Thx to all. – MadMaxAPP Nov 11 '13 at 09:04