Hexadeciaml Error

  • Thread starter Thread starter MDB
  • Start date Start date
M

MDB

Hello All, I keep getting the following error on some of my devices and it
is really inconsistent. When I get the error, I am reading XML into a
dataset. The strange thing is that it happens on the same devices everyday
even though they are configured the same as the ones that work. Even
stranger is that if I try running the same file a second time, it works
fine. Has anyone run into anything like this before?

'' '', hexadecimal value 0x00, is an invalid character.
 
Check if the Xml content that you read is a valid xml and not full of 0x00
It may happen if you forgot to "Re-position" input streams before reading/writing
xml

Ruslan Trifonov
 
Hi thanks for your response. The xml does not have any nulls or 0X00.
Also, I read the XML like this:
ds.ReadXml(Common.Classes.Globals.gstrUpdateFolderPath + "orders.xml");

How to I "Re-position" the input?
 
I can't tell what is your exact problem;however I may give you a code that
produces the same problem

//create 5 empty bytes
byte[] b = new byte[5];
//convert 5 empty bytes to string
string evilXmlChars=System.Text.Encoding.UTF8.GetString(b, 0,
b.Length);
//create bad xml
FileStream fs = new FileStream("\\badxml.xml", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write("<root>" + evilXmlChars + "</root>");
sw.Flush();
fs.Close();

//try to read it...
fs = new FileStream("\\badxml.xml", FileMode.Open);
DataSet ds = new DataSet();
//BOOOM - this is where you'll get exception: '' '', hexadecimal
value 0x00, is an invalid character
ds.ReadXml(fs);
fs.Close();


You may see in the debuger that evilXmlChars contains \0\0\0\0\0 .... and
that is exactly what the exception message says.
So I suggest digging into orders.xml file for such a char seqence.

It's strange however that you read the same xml on the second shot...
Is the order.xml one and the same on all devices or your application generates
it on the device?


What I mean with "re-positioning" is the following:
Having empty buffer may happen when you dealing with streams/buffers and
accidently you haven't set the right Stream.Poistion...but that was just
a guess.

Ruslan Trifonov
http://xman892.blgostpot.com
 
Hi, Thanks again for your response. The order.xml is the same on all
devices, they all download it from a FTP site each night and then read it
into a dataset to be saved. I will try playing around with it some more to
see if I can narrow it down. I am starting to think that maybe the file is
getting corrupted when downloaded. What makes it difficult is that I never
happens when I debug.

Thanks Again


Ruslan Trifonov said:
I can't tell what is your exact problem;however I may give you a code that
produces the same problem

//create 5 empty bytes
byte[] b = new byte[5];
//convert 5 empty bytes to string
string evilXmlChars=System.Text.Encoding.UTF8.GetString(b, 0,
b.Length);
//create bad xml FileStream fs = new FileStream("\\badxml.xml",
FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write("<root>" + evilXmlChars + "</root>");
sw.Flush();
fs.Close();

//try to read it...
fs = new FileStream("\\badxml.xml", FileMode.Open);
DataSet ds = new DataSet();
//BOOOM - this is where you'll get exception: '' '',
hexadecimal value 0x00, is an invalid character
ds.ReadXml(fs);
fs.Close();


You may see in the debuger that evilXmlChars contains \0\0\0\0\0 .... and
that is exactly what the exception message says.
So I suggest digging into orders.xml file for such a char seqence.

It's strange however that you read the same xml on the second shot...
Is the order.xml one and the same on all devices or your application
generates it on the device?


What I mean with "re-positioning" is the following:
Having empty buffer may happen when you dealing with streams/buffers and
accidently you haven't set the right Stream.Poistion...but that was just a
guess.

Ruslan Trifonov
http://xman892.blgostpot.com
Hi thanks for your response. The xml does not have any nulls or 0X00.
Also, I read the XML like this:
ds.ReadXml(Common.Classes.Globals.gstrUpdateFolderPath +
"orders.xml");

How to I "Re-position" the input?
 
Back
Top