XML Deserialization problem
-
My code is serializing a generic list of objects of class IOExtension. The IOExtension has two properties : string Name object Value The serialization occurs without issue and provides the following XML:
<Culture>
<CodeCulture xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GlobalExtensions>
<CultureItemOfIOExtension ID="" Type="MyNamespace.MyClass.IOExtension, MyNamespace.MyClass, Version=2.0.0.0, Culture=neutral, PublicKeyToken=03604d72884e7711">
<IOExtension>
<Name>GlobalExtensions</Name>
<Value xsi:type="xsd:string">GlobalValue</Value>
</IOExtension>
</CultureItemOfIOExtension>
</GlobalExtensions>
</CodeCulture>
</Culture>This is all great, except when I go to deserialize the XML I get an exception on the Value property:
Namespace prefix 'xsd' is not defined.
Now I've done some testing and it appears that this does not occur when I serialize a single instance of the IOExtension object. This would appear to be an issue with serializing the generic list of objects but I'm not sure. I've thought about implementing System.Xml.Serialization.IXmlSerializable but I'm not sure how to go about serializing the object itself. Any suggestions or thoughts out there ? I'm hoping that I can define the namespace manually somehow but obviously my knowledge of Xml Serialization is limited.
-
My code is serializing a generic list of objects of class IOExtension. The IOExtension has two properties : string Name object Value The serialization occurs without issue and provides the following XML:
<Culture>
<CodeCulture xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GlobalExtensions>
<CultureItemOfIOExtension ID="" Type="MyNamespace.MyClass.IOExtension, MyNamespace.MyClass, Version=2.0.0.0, Culture=neutral, PublicKeyToken=03604d72884e7711">
<IOExtension>
<Name>GlobalExtensions</Name>
<Value xsi:type="xsd:string">GlobalValue</Value>
</IOExtension>
</CultureItemOfIOExtension>
</GlobalExtensions>
</CodeCulture>
</Culture>This is all great, except when I go to deserialize the XML I get an exception on the Value property:
Namespace prefix 'xsd' is not defined.
Now I've done some testing and it appears that this does not occur when I serialize a single instance of the IOExtension object. This would appear to be an issue with serializing the generic list of objects but I'm not sure. I've thought about implementing System.Xml.Serialization.IXmlSerializable but I'm not sure how to go about serializing the object itself. Any suggestions or thoughts out there ? I'm hoping that I can define the namespace manually somehow but obviously my knowledge of Xml Serialization is limited.
-
Your xmlns attributes MUST be on the root element.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Hey Leppie, thanks for the response. I tried your suggestion but, unfortunately the following Xml deserialied with the same error:
<?xml version="1.0" encoding="utf-8"?>
<!--CodeCulture Culture File-->
<!--Created: 6/27/2008 8:27:23 AM-->
<!--Version: 1.0.0.0, Culture=neutral, PublicKeyToken=null-->
<!--Server: ISI-MBLDEV111-->
<CodeCulture xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Sample</Name>
<Version>1.0</Version>
<GlobalExtensions>
<CultureItemOfIOExtension ID="" Type="IOExtension, Component, Version=2.0.0.0, Culture=neutral, PublicKeyToken=03604d72884e7711">
<IOExtension>
<Name>GlobalExtensions</Name>
<StringValue>GlobalValue</StringValue>
<Value xsi:type="xsd:string">GlobalValue</Value>
</IOExtension>
</CultureItemOfIOExtension>
</GlobalExtensions>
</CodeCulture>