I'm using this code to copy data from a 2d object array into the memory stream. The memory stream shows the count of the data that has been read from the 2d array. But in the end I'm getting an empty string. I can't understand why. However, using the soapformatter, the string is not empty but it's enclosed in soap format so that isn't useful. Here's the code with BinaryFormatter.
Worksheet sheet = (Worksheet)workBookIn.Sheets[1];
Range excelRange = sheet.UsedRange;
object[,] valueArray = (object[,])excelRange.get_Value(
XlRangeValueDataType.xlRangeValueDefault);
using (var ms = new MemoryStream())
{
BinaryFormatter formatter = new BinaryFormatter();
//valueArray = 2d object array
formatter.Serialize(ms, valueArray);
ms.Position = 0;
return Encoding.UTF8.GetString(ms.ToArray());
}