What happend to nillables?

Sep 23, 2009 at 7:38 AM


I'm having several elements in the schema marked as nillable:

     <xs:element name="Nillable" type="xs:string" nillable="true" />.

In previous LinqToXsd versions (e.g. LINQ to XSD Preview Alpha 0.2) this generates classes with members which can be set explicitly to null:

     public string Nillable {
         get {
             return this.nillableField;
         set {
             this.nillableField = value;

and when set to null in my application this will be saved to correct XML instances

     <Nillable xsi:nil="true" />

This feature obviously has gone for current revision of LinqToXsd (as of changeset 17994). Here I either don't see the nulled element in the XML instance at all or I get an exception (Failed to set value on the property "accession_number". Possible reason: Value cannot be null.) for elements with further validation.

So my question is, how do I set the value of a nillable element to null?

Thanks alot,
Captain Stark

Jan 21, 2010 at 2:43 AM

I second this. I have a bunch of elements in my schema marked nillable="true", but when LinqToXsd attempts to parse elements of the form <IsSupposedToBeNillable xsi:nil="true" />, I get an exception.

Here's an example for <IsActive xsi:nil="true" />, which is defined in my schema as <xs:element name="IsActive" type="xs:boolean" nillable="true" />

A first chance exception of type 'System.FormatException' occurred in System.Xml.dll
System.Windows.Data Error: 16 : Cannot get 'IsActive' value (type 'Boolean') from '' (type 'Service'). BindingExpression:Path=IsActive; DataItem='Service' (HashCode=11344586); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String') TargetInvocationException:'System.Reflection.TargetInvocationException: Property accessor 'IsActive' on object 'NmtConcept.Models.Service' threw the following exception:'The string '' is not a valid Boolean value.' ---> System.FormatException: The string '' is not a valid Boolean value.
   at System.Xml.XmlConvert.ToBoolean(String s)
   at System.Xml.Schema.XmlBooleanConverter.ToBoolean(Object value)
   at System.Xml.Schema.XmlBooleanConverter.ChangeType(Object value, Type destinationType, IXmlNamespaceResolver nsResolver)
   at System.Xml.Schema.XmlBaseConverter.ChangeType(Object value, Type destinationType)
   at System.Xml.Schema.XmlSchemaDatatype.ChangeType(Object value, Type targetType)
   at Xml.Schema.Linq.XTypedServices.ParseValue[T](String value, XElement element, XmlSchemaDatatype datatype)
   at Xml.Schema.Linq.XTypedServices.ParseValue[T](XElement element, XmlSchemaDatatype datatype)
   at NmtConcept.Models.Service.get_IsActive() in C:\Documents and Settings\ThisUser\My Documents\Projects\ThisProject\Concept\ThisProject\ThisProject\Models\ThisProjectData.cs:line 2144