Tuesday, 1 March 2016

Showing a stream in Immediate Window (for posterity)

Recording how to show a stream's contents in Immediate Window for posterity. In this example it's the response stream when a WebClient raises an exception:

System.Text.Encoding.UTF8.GetString((byte[])$exception.Response.GetResponseStream().GetType().GetMethod("InternalGetBuffer", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke($exception.Response.GetResponseStream(), null))

(from: http://stackoverflow.com/questions/7755312/view-content-of-a-stream-in-visual-studios-quickwatch-window)

No comments:

Post a Comment