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 problem

Serialization problem

Scheduled Pinned Locked Moved C#
helpjsonquestiondiscussion
16 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.
  • Y Yoyosh 0

    1."There was an error generating the XML document." InvalidOperationException 2.This is just copy/paste issue, all code is being compiled successfully, error occurs at run-time

    A Offline
    A Offline
    AB7771
    wrote on last edited by
    #4

    Did u declare the class or the method as [Serializable]?

    Everyone is a genius at least once a year - Pramod

    Y 1 Reply Last reply
    0
    • A AB7771

      Did u declare the class or the method as [Serializable]?

      Everyone is a genius at least once a year - Pramod

      Y Offline
      Y Offline
      Yoyosh 0
      wrote on last edited by
      #5

      You right, I forgot. I mark both classes with that attribute - the class, that elemets` are kept in this structure, and class that contains Serialize method. I still get exactly the same error Please note that I cannot mark a method with that attribute: "Error 2 Attribute 'Serializable' is not valid on this declaration type. It is valid on 'class, struct, enum, delegate' declarations only. " Do you have any idea, or maybe i did something wrong?

      A 1 Reply Last reply
      0
      • Y Yoyosh 0

        You right, I forgot. I mark both classes with that attribute - the class, that elemets` are kept in this structure, and class that contains Serialize method. I still get exactly the same error Please note that I cannot mark a method with that attribute: "Error 2 Attribute 'Serializable' is not valid on this declaration type. It is valid on 'class, struct, enum, delegate' declarations only. " Do you have any idea, or maybe i did something wrong?

        A Offline
        A Offline
        AB7771
        wrote on last edited by
        #6

        You don't need to declare the method as Serializable, Declare only the classes as Serializable. If u still get error please paste the code here so that we can see wht's going wrong. Regards,

        Everyone is a genius at least once a year - Pramod

        Y 1 Reply Last reply
        0
        • A AB7771

          You don't need to declare the method as Serializable, Declare only the classes as Serializable. If u still get error please paste the code here so that we can see wht's going wrong. Regards,

          Everyone is a genius at least once a year - Pramod

          Y Offline
          Y Offline
          Yoyosh 0
          wrote on last edited by
          #7

          Sure, this is class, which object`s are kept in array/arraylist: [Serializable] public class DataGridRow { public int Time; public float Speed; public DataGridRow(int t, float s) { Time = t; Speed = s; } public DataGridRow() { } } And this is part of other class, that performs serialization: /// /// Keeps objects of type DataGridRow /// ArrayList RouteData = new ArrayList(); (...) public void Serialize() { DataGridRow[] dgr = new DataGridRow[RouteData.Count]; for (int i = 0; i < RouteData.Count; i++) { dgr[i] = (DataGridRow)RouteData[i]; } XmlSerializer a = new XmlSerializer(dgr.GetType()); StreamWriter sw = new StreamWriter(@"c:/aaa.txt"); a.Serialize(sw, RouteData); } Please let me know if I missed something (I may send it to you if you like)

          A 1 Reply Last reply
          0
          • Y Yoyosh 0

            Sure, this is class, which object`s are kept in array/arraylist: [Serializable] public class DataGridRow { public int Time; public float Speed; public DataGridRow(int t, float s) { Time = t; Speed = s; } public DataGridRow() { } } And this is part of other class, that performs serialization: /// /// Keeps objects of type DataGridRow /// ArrayList RouteData = new ArrayList(); (...) public void Serialize() { DataGridRow[] dgr = new DataGridRow[RouteData.Count]; for (int i = 0; i < RouteData.Count; i++) { dgr[i] = (DataGridRow)RouteData[i]; } XmlSerializer a = new XmlSerializer(dgr.GetType()); StreamWriter sw = new StreamWriter(@"c:/aaa.txt"); a.Serialize(sw, RouteData); } Please let me know if I missed something (I may send it to you if you like)

            A Offline
            A Offline
            AB7771
            wrote on last edited by
            #8

            OK, After going through the above code what i think is that when u are serializing u have to fetch each item from the Arraylist and serialize each object which is of the class DataGridRow, and also mention the class name in the XML Serializer constructor. Also change the file type i.e. c:\aaa.xml Try the above changes, if it works well and good if not just repost the error that u get and send the project so that we can debug and check what's going wrong.

            Thanks & Regards, Pramod "Everyone is a genius at least once a year"

            Y 1 Reply Last reply
            0
            • A AB7771

              OK, After going through the above code what i think is that when u are serializing u have to fetch each item from the Arraylist and serialize each object which is of the class DataGridRow, and also mention the class name in the XML Serializer constructor. Also change the file type i.e. c:\aaa.xml Try the above changes, if it works well and good if not just repost the error that u get and send the project so that we can debug and check what's going wrong.

              Thanks & Regards, Pramod "Everyone is a genius at least once a year"

              Y Offline
              Y Offline
              Yoyosh 0
              wrote on last edited by
              #9

              At begin I wanted to serialize the ArrayList with all elements included. Then some guy told me, that ArrayList objects can`t be serialized, but I`m sure that 1D arrays are. So thats why I copied all elements from ArrayList to Array of type DataGridRow. So I don`t think there is a must to serialize each object separately... I changed file name to aaa.xml, still I get the same error. Here you can download this whole project (112kb) thank you very much for help

              A 2 Replies Last reply
              0
              • Y Yoyosh 0

                At begin I wanted to serialize the ArrayList with all elements included. Then some guy told me, that ArrayList objects can`t be serialized, but I`m sure that 1D arrays are. So thats why I copied all elements from ArrayList to Array of type DataGridRow. So I don`t think there is a must to serialize each object separately... I changed file name to aaa.xml, still I get the same error. Here you can download this whole project (112kb) thank you very much for help

                A Offline
                A Offline
                AB7771
                wrote on last edited by
                #10

                ok what i had done is i created a class declared that serializable, declared the properties and wrote a method which was used to set values to the properties and also wrote the serialize method in the same class and then in the serialize method i used this object to serialize. The link that u have sent is blank and i could not find any project there.

                Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                A 1 Reply Last reply
                0
                • A AB7771

                  ok what i had done is i created a class declared that serializable, declared the properties and wrote a method which was used to set values to the properties and also wrote the serialize method in the same class and then in the serialize method i used this object to serialize. The link that u have sent is blank and i could not find any project there.

                  Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                  A Offline
                  A Offline
                  AB7771
                  wrote on last edited by
                  #11

                  one important thing that u have forgot is you have to declare the class as [XMLRoot "classname"] and the properties as [XMLElement "name"] try this

                  Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                  1 Reply Last reply
                  0
                  • Y Yoyosh 0

                    At begin I wanted to serialize the ArrayList with all elements included. Then some guy told me, that ArrayList objects can`t be serialized, but I`m sure that 1D arrays are. So thats why I copied all elements from ArrayList to Array of type DataGridRow. So I don`t think there is a must to serialize each object separately... I changed file name to aaa.xml, still I get the same error. Here you can download this whole project (112kb) thank you very much for help

                    A Offline
                    A Offline
                    AB7771
                    wrote on last edited by
                    #12

                    one important thing that u have forgot is you have to declare the class as [XMLRoot "classname"] and the properties as [XMLElement "name"] try this

                    Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                    Y 1 Reply Last reply
                    0
                    • A AB7771

                      one important thing that u have forgot is you have to declare the class as [XMLRoot "classname"] and the properties as [XMLElement "name"] try this

                      Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                      Y Offline
                      Y Offline
                      Yoyosh 0
                      wrote on last edited by
                      #13

                      I added these attributes - still the same result :( The link was correct, I tested it, but maybe server was down at the time you tried it. Nevertheless - this is the same project on another server: Download (I tested it and it worked) Or, if you still develope some problems with downloading, please supply mi with your @mail address again, thank you very much for helping

                      A 2 Replies Last reply
                      0
                      • Y Yoyosh 0

                        I added these attributes - still the same result :( The link was correct, I tested it, but maybe server was down at the time you tried it. Nevertheless - this is the same project on another server: Download (I tested it and it worked) Or, if you still develope some problems with downloading, please supply mi with your @mail address again, thank you very much for helping

                        A Offline
                        A Offline
                        AB7771
                        wrote on last edited by
                        #14

                        HI YOYOSH, i have downloaded the project and am working on that will send u the working code soon

                        Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                        1 Reply Last reply
                        0
                        • Y Yoyosh 0

                          I added these attributes - still the same result :( The link was correct, I tested it, but maybe server was down at the time you tried it. Nevertheless - this is the same project on another server: Download (I tested it and it worked) Or, if you still develope some problems with downloading, please supply mi with your @mail address again, thank you very much for helping

                          A Offline
                          A Offline
                          AB7771
                          wrote on last edited by
                          #15

                          i have made the neccessary changes and it's working fine can u please send me your email address, so that i can send u the project.

                          Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                          Y 1 Reply Last reply
                          0
                          • A AB7771

                            i have made the neccessary changes and it's working fine can u please send me your email address, so that i can send u the project.

                            Thanks & Regards, Pramod "Everyone is a genius at least once a year"

                            Y Offline
                            Y Offline
                            Yoyosh 0
                            wrote on last edited by
                            #16

                            it is: yoyosh@o2.pl

                            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