Asked by:
Missing Assembly Reference for System.Xml

Question
-
User142127 posted
Hello Xamarin Users. I'm new here and to Xamarin Studio and I'm having difficulty with something simple. I need to parse XML from a string and I'm trying to use System.Xml for it but the IDE is telling me that I lack an assembly reference. I've written a stackoverflow question about it and you can read it here:
http://stackoverflow.com/questions/31494879/the-type-or-namespace-name-xmldocument-could-not-be-found-are-you-missing-an/31495216?noredirect=1#comment50954764_31495216
I'm not familiar with assembly references. It appears that there are 3 sets here, one for the main project, and one for each platform (ios and android). In the main project it isn't in there and I see no way to add it except by browsing for a file. I tried to copy one of the many System.Xml.dll files to the root of my project and added it but now I get the error saying:
/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)
Saturday, July 18, 2015 10:58 PM
All replies
-
User48032 posted
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.Saturday, July 18, 2015 11:15 PM -
User142127 posted
Thank you Lori! It works!
I wish I understood better why this worked and why the other didn't.
Is System.Xml no good for PCL projects and Xamarin?
Sunday, July 19, 2015 12:17 AM -
User48032 posted
Portable Class Libraries 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. I hope this clears things up!
Sunday, July 19, 2015 2:48 AM -
User142127 posted
Thanks Lori
Would it be ok If I post your answer on my stackoverflow question? You are free to do so if you want some stackoverflow points.
Sunday, July 19, 2015 2:02 PM -
User48032 posted
@ScottYannitell awesome! I just posted it to that SO question. I didn't even think to cross post the answer. Thanks!
Sunday, July 19, 2015 9:45 PM -
User142127 posted
Thank you. I've accepted your answer
Sunday, July 19, 2015 10:51 PM