I want to deserialize a stream of bytes in a byte[] array in C#. The byte[] array is 8196 bytes long and gets its information from a TCP/IP connection.
When I give that array to the ReadObject method of System.Runtime.Serialization.Json.DataContractJsonSerializer, it throws me a SerializationException with the message “Encountered unexpected character ‘\0′”.
How could I fix this?
How are you reading the string? Generally, the ‘\0’ error points to an encoding problem. The byte stream could use a particular type of encoding, and you’re either to force an encoding of your own — or you’re deserializing in such a way that a particular encoding inconsistent with the actual encoding of the stream is being assumed.
http://social.msdn.microsoft.com/Forums/en/wcf/thread/b80c9aa7-a3d1-4aa0-b61a-35363cbc177e describes a situation where the replacement of the following line of code:
with:
fixed the problem. Perhaps something similar applies to your situation as well?