How do I view the content of a Stream in the QuickWatch window within Visual Studio?
Update
As per Daniel’s answer I used the following code –
System.Text.Encoding.UTF8.GetString((byte[])stream.GetType().GetMethod("InternalGetBuffer", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(stream, null))
You can view the content of the
MemoryStreamwithout altering it when you can make some assumptions:MemoryStreamIf you can make these assumptions, you can use the following code in your Watch window:
Disclaimer:
This might have side effects I haven’t thought of or might throw an exception in certain circumstances, so don’t use this in production code.