The type or namespace name 'XmlDocument' could not be found. Are you missing an assembly reference?

13,411

Solution 1

As I posted on the Xamarin forums: http://forums.xamarin.com/discussion/46042/missing-assembly-reference-for-system-xml#latest

Use XDocument.Parse(string) to accomplish this from your Portable Class Library.

XDocument is included in the System.Xml.Linq namespace so you will need to add the using directive for that namespace in your class.

The reason that you cannot access XmlDocument from a Portable Class Library (PCL) is due to the fact that a PCL will only expose APIs that are supported on all platforms that the PCL targets. Windows Phone 8 does not support XmlDocument, and so this isn't available in the PCL. Windows Store apps support XmlDocument but it is available in a different namespace (Windows.Data.Xml.Dom). So for this reason System.Xml.XmlDocument cannot be used from the PCL. Anything else provided through the System.Xml namespace in the PCL is fine to use.

Solution 2

You can use the following steps:

  1. Under the solution explorer on the left, right click on References and select Edit References
  2. Go to .Net Assembly or All Tab and pick the System.Xml
  3. Click OK.

Solution 3

Check if System.Xml is referenced in your project. Unfortunately I don't know how to do it in Xamarin Studio. In Visual Studio if you expand your project you will see References directory. If System.Xml is not there you can easily add it there by right-clicking on References and selecting Add Reference. After that you will be able to use XmlDocument class and entire content of System.Xml assembly.

Share:
13,411
Ohiovr
Author by

Ohiovr

I'm from central Ohio and I have lived here most of my life. I'm interested in science, computer programming, and engineering among other things. I've worked on or developed many multimedia projects involving programming, computer graphics, sound, and video (and ages ago: cd-roms). For instance I developed Phonics and Reading with McGuffey which has been downloaded over 300k times. I like Modo and Photoshop a lot and I've used Lightwave for years. I like Vegas more than premiere. I have an interest in aerial photography using quadcopters. I know a computer language that is essentially extinct these days, Lingo. If you know Lingo, drop me a line at scott at ohiovr.com I'd love to hear what you did with it.

Updated on June 04, 2022

Comments

  • Ohiovr
    Ohiovr about 2 years

    I'm trying to parse an xml document using the following:

    XmlDocument doc = new XmlDocument ();
    doc.LoadXml (myXMLstring);
    

    I get the error:

    The type or namespace name 'XmlDocument' could not be found. Are you missing an assembly reference?

    ..even though I have using System.Xml;

    I'm not sure what an assembly reference is. I'm using Xamarin Studio. I see there are several folders for references. In the references folder for the base project I don't see an entry for System.Xml

    But in individual platforms I do see System.Xml in there.

    What can I do to get this error line to clear?