title: Is XDocument.Parse different in Windows Phone 7?
body: <p>I am running the exact same code in a WP7 application and a C# 3.5 application. The WP7 application throws a <code>NotSupportedException</code> upon calling <code>XDocument.Parse()</code> while the C# 3.5 application parses the XML with no problems. Below is the code used:</p>
  
  <pre><code>WebClient client = new WebClient();
  client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadThreadsComplete);
  client.DownloadStringAsync(new Uri("http://us.battle.net/sc2/en/forum/40568/", UriKind.Absolute));
  
  ...
  
  private static void DownloadThreadsComplete(object sender, DownloadStringCompletedEventArgs e)
  {
      var doc = XDocument.Parse(e.Result);
  }
  </code></pre>
  
  <p>Any idea why this is happening? It's strange that it is failing when trying to parse an SC2 forum when a WoW forum works just fine (http://us.battle.net/wow/en/forum/984270/).</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The exception message is "NotSupportedException". Here's the full stack trace:</p>
  
  <pre><code>   at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
     at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
     at System.Xml.XmlTextReaderImpl.Read()
     at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
     at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)
     at System.Xml.Linq.XDocument.Parse(String text)
     at SC2ForumReader.Pages.ForumViewerPage.DownloadThreadsComplete(Object sender, DownloadStringCompletedEventArgs e)
     at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
     at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)
     at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark&amp; stackMark)
     at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark&amp; stackMark)
     at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
     at System.Delegate.DynamicInvokeOne(Object[] args)
     at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
     at System.Delegate.DynamicInvoke(Object[] args)
     at System.Windows.Threading.DispatcherOperation.Invoke()
     at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
     at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
     at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
     at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
     at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam&amp; pResult)
  </code></pre>
  
  <p><strong>Edit2:</strong></p>
  
  <p>I've done what was suggested and have looked at the output of the 2 different requests. Additionally in my 3.5 client application I forced the user-agent to be the same as it is in the WP7 emulator to ensure it's not the user-agent causing the issue.</p>
  
  <p>Here's the doctype declaration copied from Visual Studio:</p>
  
  <p><code>&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"&gt;</code></p>
  
  <p>The doctypes are the same in each document but there are a few discrepancies in the files that stand out (it looks like there are a few extra characters inserted on the 3.5 side):</p>
  
  <p>WP7 Emulator: <code>StarCraft II</code></p>
  
  <p>3.5 Application: <code>StarCraftÂ II</code></p>