How To Fix "There Is No Unicode Byte Order Mark" Error In C#



TODO:

You try to Deserialize a string, and receive the error "There is no Unicode byte order mark, Cannot switch to Unicode"

 

SOLUTION:

 

//If there is no UTF8 encoding in the XML, do this
string xmlString = "";  //your XML string

using (TextReader reader = new StringReader(xmlString))                             
   {                                                                             
       XmlSerializer xmlSerial = new XmlSerializer(typeof(myObject));                          
       return (myObject)xmlSerial.Deserialize(reader);                                         
   }

 

NOTES:

There are no notes on this topic.



Comments (2) -

shoaib ahmed
shoaib ahmed
8/15/2012 1:44:30 PM #

it can b solved if u just remove encoding attribute from PI(processing instruction ),ie, xml tag in your xsl file...

instead of this...

<?xml version="1.0" encoding="utf-16"?>

go for

<?xml version="1.0" ?>

in xsl file....

shoaib ahmed
shoaib ahmed
8/15/2012 1:45:50 PM #

it can b solved if u just remove encoding attribute from PI(processing instruction ),ie, xml tag in your xsl file...

instead of this...

<?xml version="1.0" encoding="utf-16"?>

go for

<?xml version="1.0" ?>

in xsl file....

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading