Exception loading an RSS feed from a file:/// URI

Topics: Argotic.Common
May 25, 2008 at 2:52 PM
I would like the ability to load an RSS feed from a file for unit testing purposes.
However I get an exception because SyndicationEncodingUtility assumes that all requests and responses are web ones.
It doesn't look like it would be too hard to check the type of the request returned from WebRequest.Create() and bypass certain code when it's not web.

Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'.
   at Argotic.Common.SyndicationEncodingUtility.CreateSafeNavigator(Uri source, ICredentials credentials, IWebProxy proxy, Encoding encoding)
   at Argotic.Syndication.RssFeed.Load(Uri source, ICredentials credentials, IWebProxy proxy, SyndicationResourceLoadSettings settings)
   at Argotic.Syndication.RssFeed.Create(Uri source, ICredentials credentials, IWebProxy proxy, SyndicationResourceLoadSettings settings)
   at Argotic.Syndication.RssFeed.Create(Uri source, SyndicationResourceLoadSettings settings)
   at Argotic.Syndication.RssFeed.Create(Uri source)
   at Sage.Platform.Mashups.Processors.FeedProcessor.ProcessRss(Uri uri) in C:\SVN\Gobi\SlxSahara\Sage\Platform\Mashups\Processors\FeedProcessor.cs:line 50
   at Sage.Platform.Mashups.Processors.FeedProcessor.OnProcess() in C:\SVN\Gobi\SlxSahara\Sage\Platform\Mashups\Processors\FeedProcessor.cs:line 38
   at Sage.Platform.Mashups.Processors.ProcessorBase.Process() in C:\SVN\Gobi\SlxSahara\Sage\Platform\Mashups\Processors\ProcessorBase.cs:line 102
May 25, 2008 at 8:38 PM

The static Create method is intended to instantiate a feed instance from an external URI specified data source. If you want to load a syndication feed from a file or other XML data source, you should use the public Load method or one of its overloads.


RssFeed feed = new RssFeed();
using(FileStream stream = new FileStream("C:\\someFile.xml"))
May 26, 2008 at 6:08 AM
I only want to use a file for the purposes of unit testing so that an internet connection is not required just to pass my tests.
Sure, I could look at Uri.Scheme and call the appropriate overload of RssFeed.Load, however don't you think it would be better if Argotic didn't make assumptions about the URI passed (ie, that it uses the HTTP scheme)?
I've updated the Argotic source and it turns out that in many cases WebRequest and WebResponse don't even need to be cast since no http specific properties are touched.

I have uploaded a zip of just the changed files here:

I have made sure that I have carefully followed your code formatting standards (gave my space bar a good workout).

Here are the steps I went through:
1. Globally replace HttpWebRequest with WebRequest.
2. Globally replace HttpWebResponse with WebResponse.
3. Remove any explicit casts that are no longer required.
4. Attempt to cast when http specific properties are touched.
5. Ensure that UseDefaultCredentials is not touched if the request is a file one (unsupported by FileWebRequest).
6. Fix all variable assignment indentation as per your formatting standards.
7. Ensure everything compiles.

I hope that you consider merging these changes into the trunk so that I don't have to maintain my modified copy.
Even if you choose not to, you should probably add lots of uri.Scheme=="http" checks so that a meaningful exception can be thrown rather than an invalid cast exception.

May 27, 2008 at 3:44 PM
If it is important to you, it is important to me. I will review your changes and work on merging the changes by the next release. Thanks for the constructive feedback!
Jun 27, 2008 at 5:04 AM
It's been a month now, has there been any progress on this?
Obviously the more time that passes before the merge, the harder it will be.
Let me know if you need me to update my patched files with any recent changes.
Jun 27, 2008 at 3:36 PM
Edited Jun 27, 2008 at 3:38 PM
This fix/feature is planned to be included in the 2008.0.2.0 release, which will hopefully be release this weekend, but work/life issues have delayed me from working on the project recently. If you are interested in contributing to the project, I am actively looking for developers.
Jul 1, 2008 at 4:12 AM
Obviously I'm keen to get this change in.
What other areas are in need of some attention?
Jul 1, 2008 at 7:48 PM
Nathan, I will be merging your proposed changes into the trunk so that you don't have to maintain my modified copy. I have created work item # 10412 to implement this feature.