gpt4 book ai didi

C# - XmlNamespaceManager 存在于 'System.Xml.ReaderWriter' (...) 和 'System.Xml (...)'

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:53 27 4
gpt4 key购买 nike

我正在将一个旧的 .dll 重写到 net.core (1.1.1) 中,其中一种方法创建了一个 XmlDocument 并通过 XmlNamespaceManager 定义了命名空间:

var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

这会在构建时抛出以下错误:

The type 'XmlNamespaceManager' exists in both 'System.Xml.ReaderWriter, Version=4.1.0.0, (...) and 'System.Xml, Version=4.0.0.0, ...

根据我看到的大多数帖子,System.Xml.ReaderWriter 是一个 NuGet,我没有安装它。我试过在 XmlNamespaceManager 前加上 System.Xml 前缀,但这没有任何区别。

编辑:

这是csproj

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<ApplicationIcon />
<OutputTypeEx>exe</OutputTypeEx>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Xml">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Xml.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>

编辑 2:

问题似乎是,每当我添加对 System.Xml 的引用时,都会添加 System.Xml.ReaderWriter。为 System.Xml 设置别名不起作用,我不知道如何为 System.Xml.ReaderWriter 设置别名。

最佳答案

问题是因为该类存在于两个 dll [Same (Namespace + TypeName)] 中,并且它无法解析您要使用哪个。

你应该 extern Alias the dll 即 alias the Dlls。在 Visual Studio 中,您可以查看 dll 属性,然后在别名列中提供别名。然后在代码中使用

引用该 dll

外部别名dllaliasname;

这应该可以消除构建错误。

看看这个链接。

https://blogs.msdn.microsoft.com/ansonh/2006/09/27/extern-alias-walkthrough/

也看看这个。

When must we use extern alias keyword in C#?

关于C# - XmlNamespaceManager 存在于 'System.Xml.ReaderWriter' (...) 和 'System.Xml (...)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43622709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com