gpt4 book ai didi

c# - 反序列化来自不同程序集的同名类

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

我收到以下运行时错误:

Types 'PaymentPortal.Payments.DataObjects.Address' and 'OurWebApp.eProc.DataFormat.Entities.Address' both use the XML type name, 'Address', from namespace ''. Use XML attributes to specify a unique XML name and/or namespace for the type

两个类具有相同的名称。我需要反序列化包含 OurWebApp.eProc.DataFormat.Entities.Address 条目的请求。我无法更改需要反序列化的类的名称,并且原始类来自第三方提供的程序集。

有什么方法可以告诉(反)序列化程序将传入的“地址”解释为 OurWebApp.eProc.DataFormat.Entities.Address 的一种类型?

最佳答案

您应该能够在 Address 类上使用 XmlType 属性 - 这将告诉 XML 模式使用“ReplaceWith”而不是“Address”

[XmlType(TypeName="ReplaceWith")]
public class Address
{
//...etc
}

更多信息 here

关于c# - 反序列化来自不同程序集的同名类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7484643/

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