tags:

views:

259

answers:

1

Hi!

I've recently used WCF to consume a REST API. I used an entity class to serialize REST XML Reponse, here's the part I have a problem:

<grid-cell-size type="decimal" nil="true"/>

and in my C# class:

[XmlElement("grid-cell-size")]
public decimal? GridCellSize { get; set; }

but the result is Input string was not in a correct format. error message.

How can I change my C# code to accept null values from XML?

A: 

Try adding the 'xsi' prefix: instead of

<grid-cell-size type="decimal" nil="true"/> 

use

<grid-cell-size xsi:type="decimal" xsi:nil="true"/> 

of course - don't forget to add the namespace to the main node: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"

namespace declarations (if not already declared)

Nissim