Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XmlDocument type not found even though I've referenced System.XML?

I've referenced System.Xml:

using System.Xml;

Then in this line:

XmlDocument xdoc = new XmlDocument();

I get:

The type or namespace name 'XmlDocument' could not be found

What could there possibly be wrong ?

Info:

.NET 3.5, C#, triple checked that it's referenced and used in the same document, been able to use similar and even child libraries (System.Linq;System.Xml.Linq;System.Xml.XPath; System.Xml;)

like image 978
Marcelo Avatar asked Apr 09 '10 13:04

Marcelo


3 Answers

Make sure your project references the System.Xml.dll assembly. It's possible that you're referencing a different assembly that contains other System.Xml.* classes and that might be why you're seeing the System.Xml namespace but without the classes you need.

If you already have this reference, try removing and re-adding it and see if that irons out some weird VS glitch.

like image 135
Keith Avatar answered Nov 18 '22 09:11

Keith


Are you perhaps working inside a SilverLight project?

Only time I have experienced this was when starting out in SilverLight, I did not realise that not all of the System.XML was in the Silverlight CLR version. I used System.Linq.XML instead.

like image 4
Daniel Elliott Avatar answered Nov 18 '22 10:11

Daniel Elliott


I know that the question is already answered, but I want to add the solution for the very similar problem that I had, which might help others:

In my case it was a simple misspelling, well, not even that, it was an uppercase-lowercase-fault:
There are 2 classes: XMLDocument (from msxml.h) and XmlDocument (from System.Xml).
Make sure that you're not mixing them up! ;-)

like image 3
Tobias Knauss Avatar answered Nov 18 '22 09:11

Tobias Knauss