Change to reset MemoryStream by creating a new instance as ms.Position=0 throws when ms is closed