开发者

Cannot serialize member 'XXX' of type System.Nullable`1[System.Decimal]. XmlAttribute/XmlText cannot be used to encode complex types [duplicate]

开发者 https://www.devze.com 2023-04-10 06:19 出处:网络
This question already has answers here: Serializing a Nullable<DateTime> in to XML (6 answers) Closed 8 years ago.
This question already has answers here: Serializing a Nullable<DateTime> in to XML (6 answers) Closed 8 years ago.

I'm getting the following error when using a web service: Cannot serialize member 'XXX' of type System.Nullable`1[System.Decimal]. XmlAttribute/XmlText cannot be used to encode complex types.

I understand the error 开发者_开发百科and found a solution on this blog: https://web.archive.org/web/20120201220703/http://www.jamesewelch.com/2009/02/03/how-to-serialize-subsonic-objects-with-nullable-properties/

I would like to use solution 2, as you will see from my comments on the blog I'm not having much luck. I'm using an ExcuteTypeList to bring the data back.

Any pointers or help would be great.

Thanks


You need to remove [XmlAttribute] and apply [XmlElement] to the XXX field.

[XmlElement(IsNullable = true)] public decimal? XXX;

public bool ShouldSerializeXXX()
{
   return XXX.HasValue;
}
0

精彩评论

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

关注公众号