This project has moved and is read-only. For the latest updates, please go here.

Invalid character in the given encoding. Line 45, position 180.

Topics: Developer Forum
May 30, 2011 at 8:43 PM

Recently, Google changed something in their blog feeds and now I'm getting the error mentioned in the title of this thread.

My customer wants to load RSS feeds from Google's blogsearch tool.

Here is an example of one of the RSS feeds that I'm loading into an RSSToolkit RSSDocument...

This RSS feed loads fine in IE and other RSS clients, and validates, but RSSToolkit chokes on it.


Is there any way to get RSSTookit to ignore such errors? (even if there is an invalid character, I'd still like to ignore that one character and get the rest of the data, if possible)

All my customer knows is that the feed works fine everywhere but my application, which is using RSSToolkit. I'd hate to have to spend the time to build my own RSSToolkit, so any help would be much appreciated.


Here's the code that throws the exception:

var rss = RssToolkit.Rss.RssDocument.Load(new System.Uri(url));

(Where url contains the URL string above)

Here's the Stack:

   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res)
   at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
   at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
   at System.Xml.XmlTextReaderImpl.ReadData()
   at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
   at System.Xml.XmlTextReaderImpl.ParseText()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.Load(String filename)
   at RssToolkit.Rss.DownloadManager.DownLoadFeedDom(String url)
   at RssToolkit.Rss.DownloadManager.GetFeedDom(String url)
   at RssToolkit.Rss.DownloadManager.GetFeed(String url)
   at RssToolkit.Rss.RssDocumentBase.Load[T](Uri url)
   at RssToolkit.Rss.RssDocument.Load(Uri url)
   at RSSToolkitTester.Form1.button1_Click(Object sender, EventArgs e) in C:\10 Development\10 VS Projects\VS9 VB\30 Windows Console Applications\FeedHarvester\RSSToolkitTester\Form1.cs:line 24

May 31, 2011 at 3:17 AM
Edited May 31, 2011 at 3:47 AM

I was encountering this same problem today and figured out a fix for it. It seemed to be a bug with the XmlDocument.Load(Url) function, because loading the same XML from a string worked. Loading the remote Url first into a string, then calling XmlDocument.Load(XmlTextReader) on an XmlTextReader from the string worked correctly.

I've upload my fix, which you can download from here:

The patch you want is 9577, which is for the DownloadManager.cs. You just need to download the source code (if you haven't already), replace DownloadManager.cs with the one I posted, recompile the project, and re-add the DLL to your own project.

By the way, this fixed the bug in the particular feed URL you reported, but not with the one I had been looking at. That one just has some invalid XML :(

Jun 5, 2011 at 4:02 AM

Thank you very much Mindwalker. This solved my problem and you saved my bacon.

I would have replied earlier, but I've been puting out fires all week. I did apply the fix on May 30th tho.