views:

859

answers:

3

I'm having an issue with deserializing an XML file with boolean values. The source XML files I'm deserializing were created from a VB6 app, where all boolean values are capitalized ("True", "False"). When I try to deserialize the XML, I'm getting a

System.FormatException: The string 'False' is not a valid Boolean value.

Is there a way to say ignore case with an attribute?

A: 

I dont think there is. You could make it string and do a comparison (String.Compare) by setting the ignoreCase value to true.

SwDevMan81
A: 

There isn't. The XML Serializer works with XML Schema, and "True" and "False" are not valid booleans.

You could either use an XML Transform to convert these two values, or you could implement the IXmlSerializable interface and do the serialization and deserialization on your own.

John Saunders
you're right John, thats what happens when you answer before eating lunch :\..but to be fair your suggestion of Xml Transform could potentially also transform a value thats not intended to be a boolean.
Stan R.
Actually, no. I would have him explicitly reference only the attributes and/or elements which are boolean. I didn't mean to transform every attribute.
John Saunders
Understood John.
Stan R.
+4  A: 

You could read that value as a string into a string field, then have a readonly bool field that had an if statement in it to return bool true or false.

Shiraz Bhaiji
You should include an example of this. You've probably got the best suggestion if you do.
John Saunders