Kevin,
I think what I'm asking is slightly different from the "bug" you refer to.
If I have this class/schema:
....
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:int"/>
....
class Customer
{
public int Id;
[XmlIgnore()]
public bool IdSpecified;
}
I can use it like this:
Customer test = new Customer();
test.Id = 2;
test.IdSpecified = true;
now send it somewhere via xml serialization and it arrives with Id=2 and
IdSpecified=true. Note there isn't any special code to set the specified
flag to true when
the Id field is set. It just happens as part of the deserialization
process.
If I have this (nillable value):
....
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:int"
nillable="true"/>
....
class Customer
{
public int? Id;
[XmlIgnore()]
public bool IdSpecified;
}
And I use it in the same way:
Customer test = new Customer();
test.Id = 2;
test.IdSpecified = true;
If I send it somewhere via xml serialization it arrives with Id=2 and
IdSpecified=false which is wrong. The specified flag is always false after
deserialization
regardless of the value of Id and of the specified flag before
serialization.
Look at these examples:
Value being sent before serialization: IdSpecified=true, Id=null
Serialized xml: <Customer> <Id
xsi:null="true" /> </Customer>
Deserialized: IdSpecified=false, Id=null
Value being sent before serialization: IdSpecified=false, Id=null or any
non-null value
Serialized xml: <Customer> </Customer>
Deserialized: IdSpecified=false, Id=null
Value being sent before serialization: IdSpecified=true, Id=4
Serialized xml: <Customer> <Id>4</</Id>
</Customer>
Deserialized: IdSpecified=false, Id=4
The serialized xml is what I would expect. The deserialized data is wrong
because there is no way to distinguish a missing (optional) value from an
explict null value.
Regards
Phil
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:Cj**************@TK2MSFTNGXA02.phx.gbl...
Hi Phil,
Thanks for your feedback. Yes, it seems to be a bug, with my search. You
can check the following link for detail.
http://lab.msdn.microsoft.com/Produc...x?feedbackid=c
1dbdc79-db80-4cc1-b392-e6f6e457db85
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."