让XmlDocument在.NET Core和.NET Framework之间进行协作

时间:2018-01-26 15:41:57

标签: c# .net .net-core xmldocument

我们最近从.NET 4.5.2将库转换为.NET Core 2.0。该库有许多返回类型XmlDocument的方法/属性。

我们还有一个应用程序(也在.NET 4.5.2中)引用了4.5.2库,现在想要使用Core版本。此应用程序对引用的库返回的文档执行某些任务。

我认为.NET Core和框架之间的XmlDocument有一些根本区别(这是我仍在努力理解和解决的部分)。但我对Core很新,但还不太了解。

以下是一些复制我的问题的简短代码:
Core 2.0库

using System.Xml;

namespace TestCoreXmlDoc
{
    public class Class1
    {
        public static XmlDocument DoAThing()
        {
            XmlDocument libDoc = new XmlDocument();
            libDoc.LoadXml("<root></root>");
            return libDoc;
        }
    }
}  

.NET 4.5.2应用程序

using System.Xml;

namespace ConsoleAppTextXmlDoc
{
    class Program
    {
        static void Main(string[] args)
        {
            //Error on below line
            XmlDocument appDoc = TestCoreXmlDoc.Class1.DoAThing();
        }
    }
}  

我看到的具体错误是:“引用类型'XmlDocument'声称它在'System.Xml.ReaderWriter'中定义,但无法找到它”。

似乎与NuGet有一些关系,但我不确定(我们目前不会将NuGet用于此应用程序,除非我们需要进行更改,否则宁愿保持这种方式。)

0 个答案:

没有答案