'これは OK Using stm As New MemoryStream() Dim writer As New BinaryWriter(stm) writer.Write(UInt16.MaxValue) writer.Write(UInt16.MaxValue) stm.Flush() stm.Position = 0 Dim reader As New BinaryReader(stm) Dim value As Integer = reader.ReadInt32() MsgBox(value) End Using
'これは「ObjectDisposedException」を引き起こす Using stm As New MemoryStream() Using writer As New BinaryWriter(stm) writer.Write(UInt16.MaxValue) writer.Write(UInt16.MaxValue) End Using stm.Flush() stm.Position = 0 Using reader As New BinaryReader(stm) Dim value As Integer = reader.ReadInt32() MsgBox(value) End Using End Using