fluter
fluter

Reputation: 13806

XmlDocument availability

I'm trying to deal with xml in a uwp app, I have added reference and usings:

using System.Xml;
using System.Xml.XPath;

But a private XmlDocument doc; throws the compiler error:

Error CS0246 The type or namespace name 'XmlDocument' could not be found (are you missing a using directive or an assembly reference?)

When I check the doc here it clearly says it is available in uwp since windows 10:

Version Information

Universal Windows Platform 
Available since 10
.NET Framework 
Available since 1.1

This type is also in .net core too.

What should I do to use this type in the app?

Upvotes: 2

Views: 238

Answers (1)

Jay Zuo
Jay Zuo

Reputation: 15758

As you've known, System.Xml.XmlDocument Class can be used in UWP apps. However, to use this class in UWP, we need to take care of Microsoft.NETCore.UniversalWindowsPlatform Package.

If you use the 5.1.0 Version of this package, then there should be no error.

But if you are using the latest stable 5.2.2 version of this package, you will get the Compiler Error CS0246 as you've mentioned.

To solve this issue, you can add System.Xml.XmlDocument Package (4.0.1 version) into your project. The project.json file might like the following.

{
  "dependencies": {
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
    "System.Xml.XmlDocument": "4.0.1"
  },
  "frameworks": {
    "uap10.0": { }
  },
  "runtimes": {
    "win10-arm": { },
    "win10-arm-aot": { },
    "win10-x86": { },
    "win10-x86-aot": { },
    "win10-x64": { },
    "win10-x64-aot": { }
  }
}

After adding the reference, you can rebuild your project, the compiler error should now disappear.

Upvotes: 3

Related Questions