Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. XML Deserialization problem

XML Deserialization problem

Scheduled Pinned Locked Moved C#
helptestingbeta-testingxmljson
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Guinness4Strength
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • G Guinness4Strength

      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.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      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)

      G 1 Reply Last reply
      0
      • L leppie

        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)

        G Offline
        G Offline
        Guinness4Strength
        wrote on last edited by
        #3

        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>

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups