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

1

11

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

Sweetheart answered 4/10, 2011 at 11:9 Comment(2)
If I'm not mistaken, your title addresses your original problem, but the question is regarding a completely different problem that you're not facing as a consequence of trying to correct the former; what exactly is the problem you're having with the ShouldSerializeX mechanism?Ninos
I'm still getting the error even when I have ShouldSerialize. If you can see my comments on the blog I think I've followed what was asked but still the errorSweetheart
F
17

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

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

public bool ShouldSerializeXXX()
{
   return XXX.HasValue;
}
Forgive answered 11/5, 2012 at 5:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.