[Mono-list] NullReferenceException on XDocument.Load

Chris Howie cdhowie at gmail.com
Thu Oct 22 13:59:59 EDT 2009


On Wed, Oct 21, 2009 at 11:04 AM, David Grant <davidgrant at gmail.com> wrote:
> Hi all,
>
> The following code throws a NullReferenceException in XDocument.Load
>
>                        Uri youTubeUrl = new
> Uri("http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed");
>                        WebClient wc = new WebClient();
>                        XmlTextReader xr = new XmlTextReader(wc.OpenRead(youTubeUrl));
>                        XDocument xdoc = XDocument.Load(xr);
>
> System.NullReferenceException : Object reference not set to an
> instance of an object
> at System.Xml.Linq.XDocument.Load (System.Xml.XmlReader reader,
> LoadOptions options) [0x00000]
> at System.Xml.Linq.XDocument.Load (System.Xml.XmlReader reader) [0x00000]
> at Tests.InnerTubeServiceTest.TestCase () [0x00000]
> at (wrapper managed-to-native)
> System.Reflection.MonoMethod:InternalInvoke
> (object,object[],System.Exception&)
> at System.Reflection.MonoMethod.Invoke (System.Object obj,
> BindingFlags invokeAttr, System.Reflection.Binder binder,
> System.Object[] parameters, System.Globalization.CultureInfo culture)
> [0x00000]
>
> Is there something wrong with my code? Or is there a bug in mono?

This looks like it may be a bug.  Perhaps wc.OpenRead is returning null?

That aside, is there a reason why you are not simply doing
XDocument.Load("http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed")?

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers


More information about the Mono-list mailing list