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. Serialization Question

Serialization Question

Scheduled Pinned Locked Moved C#
csharpquestionc++comdata-structures
6 Posts 3 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.
  • L Offline
    L Offline
    LighthouseJ
    wrote on last edited by
    #1

    I created an object class derived from System.Object and an array class derived from ArrayList. I'm trying to serialize (and deserialize) the entire thing. I found a great guide here. When I serialized in the same situation in VC++, it automatically serialized all of the objects in the array for me. All I did was write in private variables that are in the list itself, and all the objects inside the list got serialized properly too. Now, in C#, I read the file after serialization, it picks up the private array list data but it doesn't automatically serialize the objects inside of it. Not only do they not show up in the resulting file, but there's a breakpoint on the individual object serialization which never gets reached. The question is, is the array list not supposed to automatically serialize it's objects inside of it, or am I not doing something to let it automatically serialize its members? I can serialize the members using a foreach but I wanted to know what the word on this was so I don't re-invent the wheel.

    L T 2 Replies Last reply
    0
    • L LighthouseJ

      I created an object class derived from System.Object and an array class derived from ArrayList. I'm trying to serialize (and deserialize) the entire thing. I found a great guide here. When I serialized in the same situation in VC++, it automatically serialized all of the objects in the array for me. All I did was write in private variables that are in the list itself, and all the objects inside the list got serialized properly too. Now, in C#, I read the file after serialization, it picks up the private array list data but it doesn't automatically serialize the objects inside of it. Not only do they not show up in the resulting file, but there's a breakpoint on the individual object serialization which never gets reached. The question is, is the array list not supposed to automatically serialize it's objects inside of it, or am I not doing something to let it automatically serialize its members? I can serialize the members using a foreach but I wanted to know what the word on this was so I don't re-invent the wheel.

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #2

      Did you mark the class inherited from ArrayList with the [Serializable] attribute? As far as I know, serialization cannot be inherited, but I am not sure. -------- "I say no to drugs, but they don't listen." - Marilyn Manson

      L 1 Reply Last reply
      0
      • L LighthouseJ

        I created an object class derived from System.Object and an array class derived from ArrayList. I'm trying to serialize (and deserialize) the entire thing. I found a great guide here. When I serialized in the same situation in VC++, it automatically serialized all of the objects in the array for me. All I did was write in private variables that are in the list itself, and all the objects inside the list got serialized properly too. Now, in C#, I read the file after serialization, it picks up the private array list data but it doesn't automatically serialize the objects inside of it. Not only do they not show up in the resulting file, but there's a breakpoint on the individual object serialization which never gets reached. The question is, is the array list not supposed to automatically serialize it's objects inside of it, or am I not doing something to let it automatically serialize its members? I can serialize the members using a foreach but I wanted to know what the word on this was so I don't re-invent the wheel.

        T Offline
        T Offline
        tarasn
        wrote on last edited by
        #3

        You must put XMLArray and XmlArrayItem attributes as shown in code below: [XmlArray ("MyItems"), XmlArrayItem("MyItem", typeof(MyItem))] public ArrayList MyItems = new ArrayList(); The output XML should be in following form <MyItems> <MyItem/> <MyItem/> </MyItems> Of course the MyItem class must be serializable too.. :) DevIntelligence.com - My blog for .Net Developers

        L 1 Reply Last reply
        0
        • L Le centriste

          Did you mark the class inherited from ArrayList with the [Serializable] attribute? As far as I know, serialization cannot be inherited, but I am not sure. -------- "I say no to drugs, but they don't listen." - Marilyn Manson

          L Offline
          L Offline
          LighthouseJ
          wrote on last edited by
          #4

          My class that I derived from ArrayList, yeah. I have private variables associated with the list itself that are declared in the lists' class definition like counts, maximums and minimums. Those get serialized and deserialized so I know C# has no problem finding the list.

          L 1 Reply Last reply
          0
          • T tarasn

            You must put XMLArray and XmlArrayItem attributes as shown in code below: [XmlArray ("MyItems"), XmlArrayItem("MyItem", typeof(MyItem))] public ArrayList MyItems = new ArrayList(); The output XML should be in following form <MyItems> <MyItem/> <MyItem/> </MyItems> Of course the MyItem class must be serializable too.. :) DevIntelligence.com - My blog for .Net Developers

            L Offline
            L Offline
            LighthouseJ
            wrote on last edited by
            #5

            I'm trying to use the binary formatter instead of XML or Soap.

            1 Reply Last reply
            0
            • L LighthouseJ

              My class that I derived from ArrayList, yeah. I have private variables associated with the list itself that are declared in the lists' class definition like counts, maximums and minimums. Those get serialized and deserialized so I know C# has no problem finding the list.

              L Offline
              L Offline
              Le centriste
              wrote on last edited by
              #6

              Could you post the code of the 2 classes, please? -------- "I say no to drugs, but they don't listen." - Marilyn Manson

              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