Link to home
Start Free TrialLog in
Avatar of astaga
astaga

asked on

SoapFormatter - throwing exception when deserializing using MemoryStream.

Hi I have the following code:

System.Collections.Hashtable hs = new Hashtable();
hs.Add("Test1", "Data1");
hs.Add("Test2", "Data2");

MemoryStream ms = new MemoryStream();
 
SoapFormatter formatter = new SoapFormatter();
formatter.Serialize(ms, hs);

Hashtable tempHs = (Hashtable) formatter.Deserialize(ms);

The problem is that it keeps throwing an XMLException with the message : The root element is missing. Whenever i try to deserialize the data.

However, if i used exactly the same code but replace the MemoryStream with a FileStream it works fine.. THe reason I am using the memoryStream is that i dont need to write the files to disk. I just want to retrieve the byte[] .. Is there an alternative method for me to use?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of zubok32
zubok32

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial