I am trying to serialize and deserialize a object using DataContractSerializer. While doing the deserialization i.e. executing readObject function over stream data, I am facing error with exception message
There was an error deserializing the object of type. The data at the root level is invalid. Line 1, position 1
Here is the snippet of code I have used:
DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(**Object**));
dataContractSerializer.WriteObject(stream, **Object**);
// Do something
stream.seek(0, SeekOrigin.begin);
dataContractSerializer.ReadObject(stream);
I have gone through the similar error mentioned at xml.LoadData - Data at the root level is invalid. Line 1, position 1, but there we are working on string and I am not able to find length of BOM characters over stream.
Can someone provide a way out of this error?