title: C# Casting MemoryStream to FileStream
body: <p>My code is this:</p>
  
  <pre><code>byte[] byteArray = Encoding.ASCII.GetBytes(someText);
  MemoryStream stream = new MemoryStream(byteArray);
  StreamReader reader = new StreamReader(stream);
  FileStream file = (FileStream)reader.BaseStream;
  </code></pre>
  
  <p>Later I'm using file.Name.</p>
  
  <p>I'm getting an InvalidCastException: it displays follows </p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.IO.MemoryStream' to type 'System.IO.FileStream'.</p>
  </blockquote>
  
  <p>I read somewhere that I should just change FileStream to Stream. Is there something else I should do?</p>