Bug 2510 - XDocument.Parse fails to parse XML
Summary: XDocument.Parse fails to parse XML
Status: RESOLVED NORESPONSE
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 2.10.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2011-12-14 19:19 UTC by Aaron Bockover
Modified: 2013-08-09 05:04 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Aaron Bockover 2011-12-14 19:19:51 UTC
Mono does not like the XML produced by the Zune catalog web service. Attempting to parse the XML using XDocument.Parse throws an exception.

The XML is available here: http://catalog.zune.net/v3.2/en-US/apps/aab4252d-a0e0-df11-a844-00237de2db9e

The exception:


Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
Parameter name: s
  at System.IO.StringReader..ctor (System.String s) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.StringReader:.ctor (string)
  at System.Xml.Linq.XDocument.Parse (System.String s, LoadOptions options) [0x00000] in <filename unknown>:0 
  at System.Xml.Linq.XDocument.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at ZuneCatalog.<Main>m__0 (System.Object o, System.Net.DownloadStringCompletedEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Net.WebClient.OnDownloadStringCompleted (System.Net.DownloadStringCompletedEventArgs args) [0x00000] in <filename unknown>:0 
  at System.Net.WebClient.<DownloadStringAsync>m__10 (System.Object state) [0x00000] in <filename unknown>:0 
  at System.Threading.Thread.StartUnsafe () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Argument cannot be null.
Parameter name: s
  at System.IO.StringReader..ctor (System.String s) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.StringReader:.ctor (string)
  at System.Xml.Linq.XDocument.Parse (System.String s, LoadOptions options) [0x00000] in <filename unknown>:0 
  at System.Xml.Linq.XDocument.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at ZuneCatalog.<Main>m__0 (System.Object o, System.Net.DownloadStringCompletedEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Net.WebClient.OnDownloadStringCompleted (System.Net.DownloadStringCompletedEventArgs args) [0x00000] in <filename unknown>:0 
  at System.Net.WebClient.<DownloadStringAsync>m__10 (System.Object state) [0x00000] in <filename unknown>:0 
  at System.Threading.Thread.StartUnsafe () [0x00000] in <filename unknown>:0
Comment 1 Aaron Bockover 2011-12-14 19:21:43 UTC
The following works as expected in .NET 4:

using System;
using System.Linq;
using System.Net;
using System.Xml.Linq;

public static class ZuneCatalog
{
    public static void Main ()
    {
        var wc = new WebClient ();
        wc.DownloadStringCompleted += (o, e) => {
            var doc = XDocument.Parse (e.Result);
            foreach (var elem in doc.Elements ().First ().Elements ()) {
                Console.WriteLine (elem.Name);
            }
        };
        wc.DownloadStringAsync (new Uri ("http://catalog.zune.net/v3.2/en-US/apps/aab4252d-a0e0-df11-a844-00237de2db9e"));
        Console.ReadLine ();
    }
}

Running the code produces a list of elements under the root document element:

{http://www.w3.org/2005/Atom}link
{http://www.w3.org/2005/Atom}updated
{http://www.w3.org/2005/Atom}title
{http://www.w3.org/2005/Atom}id
{http://www.w3.org/2005/Atom}content
{http://schemas.zune.net/catalog/apps/2008/02}sortTitle
{http://schemas.zune.net/catalog/apps/2008/02}releaseDate
{http://schemas.zune.net/catalog/apps/2008/02}visibilityStatus
{http://schemas.zune.net/catalog/apps/2008/02}shortDescription
{http://schemas.zune.net/catalog/apps/2008/02}publisher
{http://schemas.zune.net/catalog/apps/2008/02}averageUserRating
{http://schemas.zune.net/catalog/apps/2008/02}userRatingCount
{http://schemas.zune.net/catalog/apps/2008/02}averageLastInstanceUserRating
{http://schemas.zune.net/catalog/apps/2008/02}lastInstanceUserRatingCount
{http://schemas.zune.net/catalog/apps/2008/02}image
{http://schemas.zune.net/catalog/apps/2008/02}screenshots
{http://schemas.zune.net/catalog/apps/2008/02}categories
{http://schemas.zune.net/catalog/apps/2008/02}tags
{http://schemas.zune.net/catalog/apps/2008/02}backgroundImage
{http://schemas.zune.net/catalog/apps/2008/02}publisherId
{http://www.w3.org/2005/Atom}author
Comment 2 Aaron Bockover 2011-12-14 19:24:16 UTC
new XmlDocument ().LoadXml (...) fails as well with a similar exception. Note that the XML that is downloaded and passed is valid (definitely not null), and .NET has no problem handling it.
Comment 3 Atsushi Eno 2012-01-19 05:30:20 UTC
I cannot reproduce this issue on Windows and git master on Windows.

Since XDocument.Parse() just passes the input string to StringReader, the problem rather likely occured in other areas. Make sure if the DownloadCompleted event did not result in an error (check e.Error before attempt to parse the result with XDocument).
Comment 4 Atsushi Eno 2013-08-09 05:04:36 UTC
(I wouldn't expect further response ;-)