473,383 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Deserialization Error--End Of Stream

Hello,

I am attempting to serialize an object for storage in a DB field and them deserialize it later on. I have managed to Serialize it using

private string SerializeObject(object ObjectToSerialize)
{
MemoryStream ms = new MemoryStream();
string theSerializedObject;

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
try
{
formatter.Serialize(ms, ObjectToSerialize);
byte[] thisByteArray = ms.ToArray();
theSerializedObject = Convert.ToBase64String(thisByteArray);
}
catch (System.Runtime.Serialization.SerializationExcepti on e)
{
Logs.WriteToLog("Error Serializing " + ObjectToSerialize.GetType().ToString() + " Object: " + e.Message);
throw;
}
finally
{
ms.Close();
}

return theSerializedObject;
}
I store the string returned by the above method in the DB. But I am having to trouble Deserializing it. I have the following method:

private object DeserializeObject(string StringToDeserialize)
{
object thisDeserializedObject = null;
byte[] thisByteArray = Convert.FromBase64String(StringToDeserialize);
MemoryStream ms = new MemoryStream(thisByteArray);
try
{
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();

thisDeserializedObject = formatter.Deserialize(ms);
}
catch (System.Runtime.Serialization.SerializationExcepti on e)
{
Logs.WriteToLog("Error Deserializing " + StringToDeserialize + " String: " + e.Message);
throw;
}
finally
{
ms.Close();
}

return thisDeserializedObject;
}

The deserialized method raises an error saying "End of Stream encountered before parsing was completed." when it reaches

thisDeserializedObject = formatter.Deserialize(ms);

What might be causing this? I could provide some sample data if it would help. Thanks for your help!
Nov 18 '05 #1
1 1269
Hi,

As for this post. I've replied you in another duplicated one in this group.
I'd appreciate if you have a look there. Also, if you feel convenient that
we continue to discuss in that thread, please feel free to follow up there
..Thanks.

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tom L | last post by:
Simple deserialization help needed please... I have a packet of xml in a string, and need to get that into a reader./stream of some sort so I can properly use deserialize.. here's my...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
3
by: Roy Chastain | last post by:
The following code fails with an exception of "There is an error in XML document (2, 2)." string with an inner exception of "Value cannot be null.\r\nParameter name: input" string. The inner...
1
by: BH | last post by:
I'm trying a simple object serialization and deserialization, and keep getting this error: System.Runtime.Serialization.SerializationException: Binary stream does not contain a valid...
3
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database...
3
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
2
by: andreas | last post by:
Hi, if have a object arrSdList of type SortedList for serialization and deserialization there are two subs for doing this Public Sub deser Dim Formatter As BinaryFormatter = New...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
8
by: ashoksrini | last post by:
Hi All, I have the below requirement and would like to get some feeback from the group on the best way to implement: 1. I have WSDL defined exposing few web services. 2. We dont have a...
1
by: depalau | last post by:
I'm experiencing issues where XmlSerialier.Deserialize throws an exception when attempting to use a MemoryStream built with an XmlWriter vs. a standalone StringReader. It is attempting to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.