[Mono-list] NullReferenceException on XDocument.Load
David Grant
davidgrant at gmail.com
Thu Oct 22 14:09:31 EDT 2009
On Thu, Oct 22, 2009 at 10:59 AM, Chris Howie <cdhowie at gmail.com> wrote:
> 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")?
>
You might be right wc.OpenRead might be returning null... although
you'd think new XmlTextReader(wc.OpenRead(youTubeUrl)) would throw an
exception if the argument was null. I'm not sure why I didn't do
XDocument.Load... I think I must have seen the XDocument.Load(string
str) method and assumed it took in the raw XML string but it must take
in the URI according to what you are suggesting?
Last night I ran the same code in Microsoft .NET and it worked so it
must be a bug in mono. I'd love to fix it...I compiled mono for the
first time last night and that's as far as I've gotten... Is there a
monodevelop project file for the mono libraries itself with some unit
tests?
Dave
More information about the Mono-list
mailing list