I'm having what I think will probably be a really simple problem, in developing my first WP7 app I've come to the stage of accessing my Site's api and parsing the XML, however I'm stumbling just at trying to use XDocument.
I search around and found this example code: Load an XML file from a website into XDocument (Silverlight and Windows Phone 7) but the XDocument type does not exist, I understand it is supposed to exist in the System.Xml namespace which I am using, but the error still remains, what have I missed?
Developing on Visual Studio 2010 Express for Windows Phone, code for this class is below:
using System;
using System.Net;
using System.IO;
using System.Xml;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Application
{
public class DataRetriever
{
public void parseNewsXML()
{
WebClient client = new WebClient();
client.OpenReadCompleted += (sender, e) =>
{
if (e.Error != null)
return;
Stream str = e.Result;
XDocument xdoc = XDocument.Load(str);
};
}
}
Exact error being thrown is:
Error 1 The type or namespace name 'XDocument' could not be found (are you missing a using directive or an assembly reference?)
Thanks in advance
For Silverlight, that class is in System.Xml.Linq.dll, according to MSDN - so add a reference to System.Xml.Linq.dll. You will also need a using directive at the top of your code file:
using System.Xml.Linq;
(these are exactly the same two suggestions that the compiler itself makes: "are you missing a using directive or an assembly reference?")
Related
I'm facing a very strange error in my VS2010 project that uses c# + OpenTK + Assimp.net (The packages of the last 2 are from NuGet, so I suppose them updated to their latest version)
When I try to iterate the vector3 of the UV coordinates using:
model.Meshes[n].GetTextureCoords(0)[i]
I get the following error:
error CS1061: 'Assimp.Mesh' does not contain a definition for
'GetTextureCoords' and no extension method 'GetTextureCoords'
accepting a first argument of type 'Assimp.Mesh' could be found (are
you missing a using directive or an assembly reference?)
I don't understand why! Can someone please help me?
AssimpNet is correctly referenced (I'm able to load and visualize any 3D model correctly if I comment the UV part)
And in the using part:
using System;
using System.Collections.Generic;
using System.IO; //Required by Assimp-net
using System.Reflection; //Required by Assimp-net
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using Assimp; //Required by Assimp-net
using Assimp.Configs; //Required by Assimp-net
EDIT: I also tried to change the order of the "using"s... or to remove some of them to see if there was some sort of namespace clashing but without any success
It's simply Mesh.TextureCoordinateChannels[0][i]. GetTextureCoords() does not exist. If you saw it anywhere in a tutorial, let me know where.
I am trying to process XML with C# in Visual Studio and it will not allow me to import System.Xml. I looked at other posts about this problem and this was usually caused by misspelling System.Xml to System.XML. I have the right spelling so I am not sure what is causing me problems. I looked under references and there is no System.Xml and I am using Visual Studio 2013 The error message was
Error 1 The type or namespace name 'Xml' does not exist in the namespace 'System' (are you missing an assembly reference?)
Do I have to download System.Xml?
Here is the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace WebTesting
{
class Test1
{
public static void Main(string [] args)
{
using(XmlReader reader = XmlReader.Create("myData.Xml"))
{
while(reader.Reader())
{
if(reader.IsStartElement())
{
Console.Write("The start element is " + reader.ReadString());
}
}
}
Console.ReadLine();
}
}
}
You'll need to add an assembly reference. Right-click "References" under your project in Solution Explorer and select "Add Reference..." Switch to the .NET tab and find System.Xml. Click OK.
by using XDocument (in using System.Xml.Linq;) you'll get more flexible functionality to handling XML-documents
Im trying to use LINQ in my ASP.NET/C# website. For that I need to access the class 'modelDataContext' which is a part of the LINQ namespace.
Im using Visual Studio 2010 Professional
This is my C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class admin_new_feed : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
modelDataContext data = new modelDataContext();
}
}
Full error message I get
Error 1 The type or namespace name 'modelDataContext' could not be
found (are you missing a using directive or an assembly
reference?)
Things i've tried, which doesn't solve problem
Adding the reference (Right-click solution, add reference - System.Data.Linq)
Re-create the website
Right clicking on the line, to see if the tab "Resolve" was there. But it wasn't.
I'm new to C#.
I'm trying to uncheck all checkboxes in my application using this code
foreach (CheckBox control in this.Controls.OfType<CheckBox>()) {
control.Checked = false;
}
But in this line CheckBox control in this.Controls.OfType<CheckBox>(), Controls is underlined in red. When I try to run the program, I get the following error:
Error 1 'FedApp.MainWindow' does not contain a definition for 'Controls' and no extension method 'Controls' accepting a first argument of type 'FedApp.MainWindow' could be found (are you missing a using directive or an assembly reference?)
Note I'm using the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
FedApp is the name of the application. Please how do I fix it. Thanks for any suggestion.
To enum the controls in a WPF window I think you should do something like this
foreach (object o in LogicalTreeHelper.GetChildren(FedApp.MainWindow))
{
if (o is CheckBox)
{
((CheckBox)o).Checked = false;
}
}
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.
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.
I have turned absolutely nothing up on the internet regarding this problem. Does anyone have any ideas?
EDIT: 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
Here is some sample code showing the problem:
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&user=" + app.UserName + "&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));
}
}
}
}
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?)
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?)
EDIT 2: Once I Googled what it meant to "add a reference" to a library, Anthony's answer solved the problem.
By default a Silverlight project will contain the System.Xml dll however XDcoument is contained in the System.Xml.Linq dll, this you will have to add to your project.
Make sure you add a reference to the appropriate XML library
For XMLDocument, XMLReader, etc ...: System.Xml.Dll
For XDocument, XNode, etc ...: System.Xml.Linq.dll