code snippet:
//byte[] myByteArray = byte array from database (database BLOB) myByteArray = (byte[]) ((dbCommand.Parameters['parameter'].Value)); string myString =System.Text.Encoding.UTF8.GetString(myByteArray); Xmldocument doc = new Xmldocument(); doc.Load(myString);
============
I am getting System.OutOfMemoryException sometimes.
string myString = System.Text.Encoding.UTF8.GetString(myByteArray);
when converting bytearray to string i am getting this error.
is there a way i can make this code robust.
All i am trying to do is loading the BLOB in byte array and then converting them to string and loading them in xmldocument to work with.
If you’ve got a string containing XML text, you actually want XmlDocument.LoadXML. XmlDocument.Load treats the string as a URL.
That said, XmlDocument.Load has overloads taking an XmlReader, a TextReader or a Stream. You can create a MemoryStream on the underlying byte array, and pass that; this avoids the string conversion.