Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Use XDocument class in SilverLight Project (C#)
    primarykey
    data
    text
    <p>I'm trying to create a Silverlight application (for the first time) that involves parsing XML from a site and displaying information. To do this I am using Visual Studio 2008 on Windows XP Service Pack 3. I also have .NET Framework 3.5 SP1 installed.</p> <p>My problem is that no XML-parser I have seen on the internet works. The top of my code I have both lines I believe are necessary (using "System.xml;" and using "System.linq;") but XDocument, XMLReader, XMLDocument, and any others I have found do not work, returning the error that the type or namespace cannot be found. I do have .NET Framework.</p> <p>I have turned absolutely nothing up on the internet regarding this problem. Does anyone have any ideas?</p> <p>EDIT: <strong>I just discovered that when I open the file outside of the context of a Silverlight project, it is able to use XDocument. It is only when I open the entire project that my problem occurs</strong></p> <p>Here is some sample code showing the problem: </p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Xml.Linq; //Error 1 (See below) namespace LastfmAmazon { public partial class Page : UserControl { public Page() { InitializeComponent(); } public void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { XDocument doc = XDocument.Parse(e.Result); //Error 2: see below } public void Button_Click(object sender, RoutedEventArgs e) { if (uname.Text != String.Empty) { App app = (App)Application.Current; app.UserName = uname.Text; String getTopArtists = "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&amp;user=" + app.UserName + "&amp;api_key=d2d620af554a60f228faed8d502c4936"; uname.Text = "Try Another One!"; WebClient web = new WebClient(); WebClient client = new WebClient(); client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompleted); client.DownloadStringAsync(new Uri(getTopArtists)); } } } } </code></pre> <p>Error 1: This line contains the following error: The type or namespace name 'Linq' does not exist in the namespace 'System.Xml' (are you missing an assembly reference?)</p> <p>Error 2: This line contains the following error: The type or namespace name 'XDocument' does not exist in the namespace 'System.Xml' (are you missing an assembly reference?)</p> <p>EDIT 2: Once I Googled what it meant to "add a reference" to a library, Anthony's answer solved the problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload