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

I am trying to parse an XML document using the following:

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

      

I am getting the error:

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

.. although I have using System.Xml;

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

But on separate platforms, I see System.Xml.

What can I do to clear this error line?

+3


source to share


4 answers


As I wrote 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 namespace System.Xml.Linq

, so you will need to add a use directive for that namespace in your class.

The reason you cannot access XmlDocument

from Portable Class Library (PCL) is because PCL will only expose APIs that are supported on all platforms that PCL targets. Windows Phone 8 does not support XmlDocument and therefore it is not possible in PCL. Windows Store apps support XmlDocument but are available in a different namespace ( Windows.Data.Xml.Dom

). Therefore, for this reason, System.Xml.XmlDocument

it cannot be used from PCL. Anything in the namespace System.Xml

in the PCL is great to use.

+6


source


You can use the following steps:



  • In the solution explorer on the left, right click on References and select Edit References
  • Go to .Net Assembly or All tab and select System.Xml
  • Click OK.
+4


source


Check if System.Xml is referenced in your project. Unfortunately I don't know how to do this in Xamarin Studio. In Visual Studio, if you expand your project, you will see a directory of links. If System.Xml doesn't exist, you can easily add it there by right-clicking on the links and choosing Add Link. Then you can use the XmlDocument class and all the content of the System.Xml assembly.

0


source


Just add to your source code

using Windows.Data.Xml.Dom;

      

0


source







All Articles