Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 321
Ohiovr Avatar asked Dec 11 '22 22:12

Ohiovr


1 Answers

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.

like image 119
Lori Lalonde - MSFT Avatar answered Mar 30 '23 01:03

Lori Lalonde - MSFT