6

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;)

ALOToverflow
  • 2,679
  • 5
  • 36
  • 70
Marcelo
  • 3,371
  • 10
  • 45
  • 76
  • 1
    Have you tried creating a new project from scratch? I can't seem to get this to happen and wonder if there's some version mismatch or project corruption going on. – Jesse C. Slicer Apr 09 '10 at 13:43

5 Answers5

10

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.

Keith
  • 20,636
  • 11
  • 84
  • 125
4

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Daniel Elliott
  • 22,647
  • 10
  • 64
  • 82
3

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! ;-)

Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45
1

I know this is a very old question but the problem persists nowadays. I'm on a Xamarin.Forms project and the PCL project targets a profile (Profile111) that doesn't support XmlDocument. I had to use System.Xml.Linq.XDocument. My projects targets WindowsPhone and XmlDocument doesn't exist on this target.

Tiago Freitas Leal
  • 693
  • 1
  • 7
  • 13
0

If you're using Visual Studio Code, you need to include the .NET Standard package from NuGet. You can also just include the System.Xml.XmlDocument package directly if that's all you need.

kop48
  • 505
  • 3
  • 8