title: System.Xml.XmlException: Invalid character in the given encoding. Line 8271, position 163
body: <p>I am writing a simple XML parser which would pass this XML output: <a href="http://www.cpalead.com/dashboard/reports/campaign_rss.php?id=187000" rel="nofollow">http://www.cpalead.com/dashboard/reports/campaign_rss.php?id=187000</a></p>
  
  <p>The full C# code is: </p>
  
  <pre><code>    protected void LoadXML()
      {
          XDocument ourBlog = XDocument.Load("http://www.cpalead.com/dashboard/reports/campaign_rss.php?id=187000");
          ourBlog.Declaration.Encoding = "ISO-8859-1";
          XNamespace NameSpace = "http://www.cpalead.com/feeds/campinfo.php";
          var XMLItem = from item in ourBlog.Descendants("item")
                        select new
                        {
                            title = item.Element("title").Value,
                            link = item.Element("link").Value,
                            guid = item.Element("guid").Value,
                            description = item.Element("description").Value,
                            campinfoamount = item.Element(NameSpace + "amount").Value,
                            campinfocampid = item.Element(NameSpace + "campid").Value,
                            campinfocountry = item.Element(NameSpace + "country").Value,
                            campnfotype = item.Element(NameSpace + "type").Value,
                            campinfoepc = item.Element(NameSpace + "epc").Value,
                            campinforatio = item.Element(NameSpace + "ratio").Value
                        };
  
          foreach (var item in XMLItem)
          {
              offers.InnerHtml += item.title + item.campinforatio + "&lt;br&gt;";
          }
  
      }
  </code></pre>
  
  <p>offers is a div element.
  When I run this code I get an "System.Xml.XmlException: Invalid character in the given encoding. Line 8271, position 163." error
  As you can see I also set Encoding using ourBlog.Declaration.Encoding = "";
  I have tried:</p>
  
  <ul>
  <li>ISO-8859-1</li>
  <li>UTF-8</li>
  <li>windows-1251</li>
  <li>windows 1252</li>
  <li>UTF-16</li>
  </ul>
  
  <p>I don't know what else to try.
  Do you have any suggestions?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Stack Trace is: </p>
  
  <p>Source Error: </p>
  
  <pre><code>Line 19:         protected void LoadXML()
  Line 20:         {
  Line 21:             XDocument ourBlog = XDocument.Load("http://www.cpalead.com/dashboard/reports/campaign_rss.php?id=187000");
  Line 22:             ourBlog.Declaration.Encoding = "ISO-8859-1";
  Line 23:             XNamespace NameSpace = "http://www.cpalead.com/feeds/campinfo.php";
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <pre><code>[XmlException: Invalid character in the given encoding. Line 8271, position 163.]
  System.Xml.XmlTextReaderImpl.Throw(Exception e) +69
  System.Xml.XmlTextReaderImpl.Throw(String res, String arg) +116
  System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32&amp; bytesCount, Int32&amp; charsCount) +197
  System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount) +131
  System.Xml.XmlTextReaderImpl.ReadData() +188
  System.Xml.XmlTextReaderImpl.ParseText(Int32&amp; startPos, Int32&amp; endPos, Int32&amp; outOrChars) +482
  System.Xml.XmlTextReaderImpl.FinishPartialValue() +62
  System.Xml.XmlTextReaderImpl.get_Value() +74
  System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r) +505
  System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o) +48
  System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) +283
  System.Xml.Linq.XDocument.Load(String uri, LoadOptions options) +58
  System.Xml.Linq.XDocument.Load(String uri) +6
  WebApplication3.Earn._default.LoadXML() in c:\Users\WinDrop\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\Earn\default.aspx.cs:21
  WebApplication3.Earn._default.Page_Load(Object sender, EventArgs e) in c:\Users\WinDrop\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\Earn\default.aspx.cs:16
  System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
  System.Web.UI.Control.OnLoad(EventArgs e) +92
  System.Web.UI.Control.LoadRecursive() +54
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
  </code></pre>