title: Memory stream exception C#
body: <p>I am trying to let user download image that is stored in database as base64 string, which works fine but when I inspect <code>stream</code> while debugging I get</p>
  
  <blockquote>
    <p><code>stream.ReadTimeout</code> threw an exception of type <code>System.InvalidOpertationException</code>  </p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p><code>stream.WriteTimeout</code> threw an exception of type <code>System.InvalidOpertationException</code>  </p>
  </blockquote>
  
  <p>So I'd like to know if this could cause major problems for me.</p>
  
  <pre><code>[HttpGet]
          public IHttpActionResult DownloadImage(int id)
          {
              try
              {
                  var bill = _billFactory.Get(id);
                  var attachment = bill.Attachment;
                  byte[] img = Encoding.Unicode.GetBytes(attachment);
  
                  MemoryStream stream = new MemoryStream(img);
                  HttpResponseMessage httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
                  {
                      Content = new StreamContent(stream)
                  };
  
                  httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                  {
                      FileName = "image.jpg"
                  };
  
                  httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
  
                  ResponseMessageResult responseMessageResult = ResponseMessage(httpResponseMessage);
                  return responseMessageResult;
  
              }
              catch (Exception ex)
              {
                  throw;
              }
          }
  </code></pre>