gpt4 book ai didi

c# - 以编程方式将 dependentAssembly 添加到 runtime\assemblyBinding

转载 作者:行者123 更新时间:2023-11-30 12:16:52 25 4
gpt4 key购买 nike

我试图在运行时向我的 Web.config 文件添加一个新的 dependentAssembly。到目前为止,我当前的代码有

    XmlNamespaceManager manager = new XmlNamespaceManager (WebConfigDoc.NameTable);
manager.AddNamespace("bindings", "urn:schemas-microsoft-com:asm.v1");

XmlNode root = WebConfigDoc.DocumentElement;

XmlNode assemblyBinding = root.SelectSingleNode("//bindings:assemblyBinding", manager);

XmlNode newAssemblyBinding = WebConfigDoc.ImportNode(GetElement(MyNewNode()), true);

assemblyBinding.AppendChild(newAssemblyBinding);
}

private string MyNewNode()
{
string Node = "<dependentAssembly>" +
"<assemblyIdentity name=\"newone\" "+
" publicKeyToken=\"608967\" />" +
"<bindingRedirect oldVersion=\"1\" newwVersion=\"2\" />" +
"</dependentAssembly>";
return Node ;
}

这有效,但结果节点是这样的

<dependentAssembly xmlns="">
<assemblyIdentity name="newone" publicKeyToken="608967" />
<bindingRedirect oldVersion="1" newVersion="2" />
</dependentAssembly>

我不需要附加 xmlns="" 属性。

有更好的方法吗?

谢谢。

最佳答案

问题是因为您要添加的新节点位于“无命名空间”中,而父节点位于“urn:schemas-microsoft-com:asm.v1”命名空间中。

解决方案:

改变:

  string Node = "<dependentAssembly>" + 

:

  string Node = "<dependentAssembly xmlns='urn:schemas-microsoft-com:asm.v1'>" + 

关于c# - 以编程方式将 dependentAssembly 添加到 runtime\assemblyBinding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4512259/

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