c# - FormatException on Reading XML into DataTable -
i'm using function datatable.readxml(textreader) convert xml datatable following code:
datatable table = new datatable("document"); ... (add columns table) textreader textreader = new stringreader(xmlstring); table.readxml(textreader);
the xml generated other server. (dms)
this works fine on every machine. on 1 windows 8.1 computer expression throws following error:
system.formatexception: die eingabezeichenfolge hat das falsche format. bei system.number.parsesingle(string value, numberstyles options, numberformatinfo numfmt) bei system.single.parse(string s, numberstyles style, iformatprovider provider) bei system.xml.xmlconvert.tosingle(string s) bei system.data.common.singlestorage.convertxmltoobject(string s) bei system.data.xmldataloader.loadcolumn(datacolumn column, object[] foundcolumns) bei system.data.xmldataloader.loadtable(datatable table, boolean isnested) bei system.data.xmldataloader.loaddata(xmlreader reader) bei system.data.datatable.readxml(xmlreader reader, boolean denyresolving)
by try , error testing found out, following problem ocurs: there date in format yyyy-mm-dd in 1 xml node. somehow method readxml can't parse date on specific machine.
the culture on both (the working , not working) machines is: thread.currentthread.currentculture: de-ch thread.currentthread.currentuiculture: de-de
when change system culture on not working system en-ca. works correct.
what problem? how can solve it?
here example xml: xml looks like:
<?xml version="1.0" encoding="utf-16"?> <documentinfo> <documentlist> <doccount>1</doccount> <foundmore>false</foundmore> <document> <docid>kg0000001</docid> <doctype>01. administration</doctype> <doctypeshort>dadmi</doctypeshort> <docnumber>b_10000</docnumber> <lastreleasedversion>0</lastreleasedversion> <importdate>2014-05-22</importdate> <docstate>freigabe</docstate> <filetype>pdf</filetype> <filesizebytes>678617</filesizebytes> <filesizekb>662.71</filesizekb> <originalfilename>b_10000</originalfilename> <docchangedat>2014-05-22</docchangedat> <origin/> <dok_dat_feld_1>39099</dok_dat_feld_1> <dok_dat_feld_2>11364</dok_dat_feld_2> <dok_dat_feld_3>anträge</dok_dat_feld_3> <dok_dat_feld_4>fragen.pdf</dok_dat_feld_4> <dok_dat_feld_9>männlich</dok_dat_feld_9> <dok_dat_feld_12>6.41.11.72</dok_dat_feld_12> <dok_dat_feld_13>nein</dok_dat_feld_13> <dok_dat_feld_21>jxxx</dok_dat_feld_21> <dok_dat_feld_50>2013-11-27</dok_dat_feld_50> <dok_dat_feld_51>2014-04-08</dok_dat_feld_51> <dok_dat_feld_54>2014-05-22</dok_dat_feld_54> </document> </documentlist> </documentinfo>
you can fix doing this:
datatable table = new datatable(); table.locale = cultureinfo.invariantculture;
the other solution seems to change creation of xml use writexml equivalent.
Comments
Post a Comment