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. Visual Basic
  4. Serialize the class

Serialize the class

Scheduled Pinned Locked Moved Visual Basic
helpwcfxmljson
5 Posts 4 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.
  • P Offline
    P Offline
    ParagGupta
    wrote on last edited by
    #1

    Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag

    K D E 3 Replies Last reply
    0
    • P ParagGupta

      Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      You could change the name of one of them. Or you could mark one of them as none serializiable. Hope that helps. Ben

      1 Reply Last reply
      0
      • P ParagGupta

        Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        The problem is that in the XML file, both City properties will have the same exact name. This obviously won't work. So, you have to change the name of one of the City properties in the file, not necessarily in your code. This is easily done if you use the XmlElement attribute on the property definition:

        <XmlElement(ElementName = "AddrCity")> \_
        Public Property City() As String
            ...
        

        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        1 Reply Last reply
        0
        • P ParagGupta

          Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag

          E Offline
          E Offline
          Eugene Ciloci
          wrote on last edited by
          #4

          ParagGupta wrote:

          I and using SOAP for serialization

          You could also switch to binary serialization which doesn't have this limitation.... In my experience, SOAP serialization is not very practical. Once you start serializing a realistic number of objects, the size of the output grows very rapidly. You can also tell that Microsoft is moving away from it since it doesn't support generics.

          P 1 Reply Last reply
          0
          • E Eugene Ciloci

            ParagGupta wrote:

            I and using SOAP for serialization

            You could also switch to binary serialization which doesn't have this limitation.... In my experience, SOAP serialization is not very practical. Once you start serializing a realistic number of objects, the size of the output grows very rapidly. You can also tell that Microsoft is moving away from it since it doesn't support generics.

            P Offline
            P Offline
            ParagGupta
            wrote on last edited by
            #5

            Hi, Well thanks for all your responses. But I cant use any of these as the porblem using these are : 1. I dont know which properties it will use and so i cant change the name. 2. Binary cant be used as it wont support if i made any changes for reading/writing from/in the file. Isn't there any method that can distinguish each into different regions like ......... all the properties in employee....... <\employee>

            ........ all the properties in address......... <\address> .......

            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