Anzar Khatri

Anzar Khatri

  • NA
  • 13
  • 8.8k

C# exception when converting >400MB stream to byte array

Dec 5 2013 2:10 PM

After searching a lot and becoming confused and disapointed I want to post my question here. I had encountered problem of OutofMemoryException when using MemoryStream and finally got around with the help of MemoryTributary. Another problem still remains. I want to convert that stream to byte array but again get OutofMemoryException error when converting MemoryTributary (or even MemoryStream. I do not use MemoryStream now because it cant handle large memory) stream to byte array on windows XP while same code is running without thowing that error on Windwos 7. Follwoing is code:

DataContractSerializer ds = new DataContractSerializer(typeof(List<DataItem>));
MemoryTributary stream2 = new MemoryTributary();
ds.WriteObject(stream2, tempdataitems);
byte[] data = stream2.ToArray(); // OutofMemoryException 

My machine is core2 with 4GB RAM. I know this is not problem with RAM.  Help is appreciated in solving this problem. I have to run that code on  WinXP.


Answers (4)