title: How do I print the content of a Stream when the content type is application/octet-stream?
body: <p>I'm trying to intercept .NET Remoting Request/Responses by implementing a ServerChannelSink.
  All is well, apart from the fact that I can't seem to decode the stream into a string. How do I do this?</p>
  
  <p>Basically, in the watch window I can see that a value has been assigned to my variable after running the code: -
  <img src="https://i.stack.imgur.com/ncDll.jpg" alt="enter image description here"></p>
  
  <p>But if I open the Text Visualizer it is empty.
  Similarly if I try to write the string to the Output window I don't get any lines written.</p>
  
  <p>Here is the code that I'm using:</p>
  
  <pre><code>    private static void PrintStream(TextWriter output, ref Stream stream)
      {
          // If we can't reset the stream's position after printing its content,
          //   we must make a copy.
          if (!stream.CanSeek)
              stream = CopyStream(stream);
  
          long startPosition = stream.Position;
  
          byte[] buffer = new byte[stream.Length];
  
          stream.Read(buffer, 0, (int)stream.Length);
  
          System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
  
          string request = enc.GetString(buffer, 0, buffer.Length);
  
          output.WriteLine(request);
  
          output.WriteLine();
  
          // set stream to previous position for message processing
  
          stream.Seek(startPosition, SeekOrigin.Begin);
      }
  </code></pre>
  
  <p>I've also tried using a StreamReader with the same result:</p>
  
  <pre><code>    private static void PrintStream(TextWriter output, ref Stream stream)
      {
          // If we can't reset the stream's position after printing its content,
          //   we must make a copy.
          if (!stream.CanSeek)
              stream = CopyStream(stream);
  
          long startPosition = stream.Position;
  
          StreamReader sr = new StreamReader(stream);
          String line;
          while ((line = sr.ReadLine()) != null)
          {
              output.WriteLine(line);
          }
  
          stream.Position = startPosition;
      }
  </code></pre>