我试图将流写入内存而不是文件中。我尝试了以下方法:
Stream stream = new MemoryStream();
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, objectToSerialize);
stream.Close();
return stream;
但是当我在写入数据后查看流时,它会显示“Length = 'stream.Length' threw an exception of type 'System.ObjectDisposedException'”。