title: XmlException: Invalid character in the given encoding
body: <p>I have an UTF-8 encoded xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  </code></pre>
  
  <p>When using below version of xml reader. I am assuming this uses UTF-8 enoding to parse xml file.</p>
  
  <pre><code> using (XmlReader reader = XmlReader.Create(inputUri))
  </code></pre>
  
  <p>I am getting below exception.</p>
  
  <pre><code>System.Xml.XmlException occurred
    HResult=-2146232000
    LineNumber=18750
    LinePosition=13
    Message=Invalid character in the given encoding. Line 18750, position 13.
  </code></pre>
  
  <p>But when using  below version of xmlreader  </p>
  
  <pre><code>using (XmlReader reader = XmlReader.Create(new StreamReader(inputUri,Encoding.UTF8)))
  </code></pre>
  
  <p>The xml gets parsed successfully. Why such differences between these two versions given both uses same encoding to parse the given xml file??</p>
  
  <p>PS: I am pretty much sure the first version uses UTF-8 endoding.</p>
  
  <p>Below is the snippet from <strong>XmlTextReaderImpl.cs</strong> whose instance is returned by the first version.</p>
  
  <pre><code>        private void SetupEncoding( Encoding encoding ) {
              if ( encoding == null ) {
                  Debug.Assert( ps.charPos == 0 );
                  ps.encoding = Encoding.UTF8;
                  ps.decoder = new SafeAsciiDecoder(); // This falls back to UTF-8 decoder
              }
  }
  </code></pre>