I am Serializing a class object and storing in sqlite database as BLOB from a C# application.
Function used for serializing: public static byte[] ObjectToByteArray (AnalyzeSubstring obj)
And on other application, fetching the blob database and converting blob database in to the object by deserializing.
function for deserializing is :public static AnalyzeSubstring ByteArrayToObject (byte[] arrBytes)
public static byte[] ObjectToByteArray (AnalyzeSubstring obj)
{
if ( obj == null )
return null;
BinaryFormatter bf = new BinaryFormatter ();
//bf.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, obj);
return ms.ToArray ();
}
public static AnalyzeSubstring ByteArrayToObject (byte[] arrBytes)
{
MemoryStream memStream = new MemoryStream ();
BinaryFormatter binForm = new BinaryFormatter ();
memStream.Write (arrBytes, 0, arrBytes.Length);
memStream.Seek (0, SeekOrigin.Begin);
AnalyzeSubstring obj = (AnalyzeSubstring) binForm.Deserialize (memStream);
return obj;
}
Issue:In line while deserializing AnalyzeSubstring obj = (AnalyzeSubstring) binForm.Deserialize (memStream);
.
It fails with error
Object reference not set to an instance of an object .
However if we do both operation in same application only, then this work properly.
Please help