我正在尝试在uwp应用程序中处理xml,我添加了引用和使用:
using System.Xml;
using System.Xml.XPath;
但是private XmlDocument doc;
会抛出编译器错误:
错误 CS0246 找不到类型或命名空间名称"XmlDocument"(是否缺少 using 指令或程序集引用?
当我在这里检查文档时,它清楚地表明它自 Windows 10 以来在 uwp 中可用:
Version Information
Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
这种类型也在 .net 核心中。
在应用程序中使用此类型应该怎么做?
如你所知,System.Xml.XmlDocument Class 可以在 UWP 应用中使用。但是,要在UWP中使用此类,我们需要处理Microsoft.NETCore.UniversalWindowsPlatform Package。
如果您使用此软件包的 5.1.0 版本,则应该没有错误。
但是,如果您使用的是此软件包的最新稳定版 5.2.2,您将获得您提到的Compiler Error CS0246
。
若要解决此问题,可以将 System.Xml.XmlDocument 包(4.0.1 版本)添加到项目中。project.json 文件可能如下所示。
{
"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": { }
}
}
添加引用后,可以重新生成项目,编译器错误现在应该消失了。