开发者

Deserialize classes with the same name from different assemblies

开发者 https://www.devze.com 2023-04-05 22:44 出处:网络
I am getting the following runtime error: Types \'PaymentPortal.Payments.DataObjects.Address\' and \'OurWebApp.eProc.DataFormat.Entities.Address\' both use the XML type name, \'Address\', from names

I am getting the following runtime error:

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

Both classes have the same name. I need to deserialize a request containing an OurWebApp.eProc.DataFormat.Entities.Address entry. I cannot change the name of the classes I开发者_高级运维 need deserialized and the original class is from an assembly that is third-party provided.

Is there any way I can tell the (de)serializer to interpret the incoming 'Address' as a type of OurWebApp.eProc.DataFormat.Entities.Address?


You should be able to use the XmlType attribute on your Address class - this will tell the XML Schema to use "ReplaceWith" instead of "Address"

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

More info here


Can you specify a namespace on your Address class?

[XmlType(Namespace = "http://OurWebApp.eProc.com")]
public class Address { }

That should prevent any collisions in the serialization.

0

精彩评论

暂无评论...
验证码 换一张
取 消