In my solution to serialize data with the model and stored as bit array in SQL and it retrieving the bit array and then Deserialize with the same model. In the model we have done one change. The existing property changed to shorthand property as below.
Existing code
[Serializable()]
public abstract class SearchResultModel : ISearchResultModel
{
private Guid id;
public Guid ID
{
get { return this.id; }
set { this.id = value; }
}
}
And its changed as below
[Serializable()]
public abstract class SearchResultModel : ISearchResultModel
{
public Guid ID { get; set; }
}
The data is serialize and deserialize with both new and old model. But the problem is that when we retrieve old model serialized bit-array trying to deserialize with new Model the ID become GUID.Empty
.
The code for serialize and deserialize has no change.
---------------For Deserialize-----
MemoryStream stream = new MemoryStream(searchResultInfoData);
stream.Position = 0;
BinaryFormatter formatter = new BinaryFormatter();
var searchResultInfo = (SearchResultModel)formatter.Deserialize(stream);
stream.Flush();
stream.Close();
return searchResultInfo;
---------------For Serialize-----
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, instance); //instance type is Object
stream.Seek(0, 0);
stream.Position = 0; //Return to start
byte[] byteArray = stream.ToArray();
stream.Flush();
stream.Close();
return byteArray;
With the both model data is already stored. How we can resolve this? Did I missing something?