I am using multiple memory streams to convert my file names to stream and write in them like so:
public static void Save() {
try {
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("Clients.txt"))) {
using(StreamWriter sw = new StreamWriter(ms)) {
writeClients(sw);
} */ Line 91 */
}
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes("Hotels.txt"))) {
using(StreamWriter sw = new StreamWriter(ms)) {
writeHotels(sw);
}
}
[...]
} catch {
[...]
}
}
but somehow when I call Save()
I get the following error:
Unhandled Exception: System.NotSupportedException: Memory stream is not expandable.
at System.IO.__Error.MemoryStreamNotExpandable()
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Dispose(Boolean disposing)
at System.IO.TextWriter.Dispose()
at csharp.Program.Save() in /home/nids/Documents/csharp/Program.cs:line 91
at csharp.Program.Main(String[] args) in /home/nids/Documents/csharp/Program.cs:line 290
Where line 290 is the line where I call Save()
I'm not sure what's causing the error!