4

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?

Ohiovr
  • 977
  • 1
  • 12
  • 22
  • 1
    Add : using System.Xml; If still issue, then from menu Project : Reference : Add Reference : .Net tab : System.Xml – jdweng Jul 18 '15 at 20:15
  • What is the project type of xml2? Some project types just don't allow such references to be added. – Lex Li Jul 19 '15 at 03:31

4 Answers4

8

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.

4

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.
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
  • Hello, thank's for the suggestion. However this is what I see when I do as you suggest: http://ohiovr.com/xfer/assembly.JPG I don't see an add button – Ohiovr Jul 18 '15 at 20:50
  • Go to All Tab and check..if you find it select it and then click Ok. – Salah Akbari Jul 18 '15 at 20:52
  • in .Net Assembly Tab you can see Browse Button. Try find System.Xml in your computer and Add to your project in this way. – Salah Akbari Jul 18 '15 at 21:07
  • Actually I seem to have acumlated dozens of these System.Xml.dll files. If I just copy one of them willy nilly and add it to my root folder I can add it in the way that you mentioned. However now I get the error "/Users/Scott/Projects/xml2/xml2/CSC: Error CS1703: An assembly `System.Xml' with the same identity has already been imported. Consider removing one of the references (CS1703) (xml2)" – Ohiovr Jul 18 '15 at 22:00
  • if you already have this reference, try removing and re-adding it. – Salah Akbari Jul 19 '15 at 05:06
1

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.

Divh
  • 303
  • 1
  • 4
  • 14
0

Just add to source

using Windows.Data.Xml.Dom;
Andris
  • 9
  • 1