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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Serialization load/save getting a different HashCode....

Serialization load/save getting a different HashCode....

Scheduled Pinned Locked Moved C#
sysadminjsonhelpquestion
6 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.
  • G Offline
    G Offline
    Guilherme Morais
    wrote on last edited by
    #1

    Hi there... I´m facing a strange problem... I made a WebApp which serializate a complex object and save in the bank and load to save time of processor. When the WebApp save and read the object everything goes fine, but If I install one second WebApp in other server the same object is readed but the HashCode is differently from the original... Anyone has a opnion about that?? Thanks in advance...

    N W L 3 Replies Last reply
    0
    • G Guilherme Morais

      Hi there... I´m facing a strange problem... I made a WebApp which serializate a complex object and save in the bank and load to save time of processor. When the WebApp save and read the object everything goes fine, but If I install one second WebApp in other server the same object is readed but the HashCode is differently from the original... Anyone has a opnion about that?? Thanks in advance...

      N Offline
      N Offline
      Natza Mitzi
      wrote on last edited by
      #2

      This is strange. You should try to compare and see if they are the same (time stamps and everything) If you can not find anything override the default Objectt.GetHashcode function and write your own. If you have an id for the object just use return id.GetHashCode(); in the override.

      Natza Mitzi

      L 1 Reply Last reply
      0
      • G Guilherme Morais

        Hi there... I´m facing a strange problem... I made a WebApp which serializate a complex object and save in the bank and load to save time of processor. When the WebApp save and read the object everything goes fine, but If I install one second WebApp in other server the same object is readed but the HashCode is differently from the original... Anyone has a opnion about that?? Thanks in advance...

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #3

        I suppose this is normal behaviour. There are no guarantees that the hash code is the same when retrieved for an object nor that it is unique. If you want to predict the value of the hashcode (for example that it stays the same), you must build your own implementation. From BOL: The default implementation of the GetHashCode method does not guarantee unique return values for different objects. Furthermore, the .NET Framework does not guarantee the default implementation of the GetHashCode method, and the value it returns will be the same between different versions of the .NET Framework. Consequently, the default implementation of this method must not be used as a unique object identifier for hashing purposes.

        1 Reply Last reply
        0
        • G Guilherme Morais

          Hi there... I´m facing a strange problem... I made a WebApp which serializate a complex object and save in the bank and load to save time of processor. When the WebApp save and read the object everything goes fine, but If I install one second WebApp in other server the same object is readed but the HashCode is differently from the original... Anyone has a opnion about that?? Thanks in advance...

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

          You need to override GetHashCode() and provide your own consistent behaviour.

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          1 Reply Last reply
          0
          • N Natza Mitzi

            This is strange. You should try to compare and see if they are the same (time stamps and everything) If you can not find anything override the default Objectt.GetHashcode function and write your own. If you have an id for the object just use return id.GetHashCode(); in the override.

            Natza Mitzi

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

            Natza Mitzi wrote:

            This is strange.

            It is not strange, it's perfect normal behaviour. I suggest you read about the topic a bit more. It has 'bitten' me a few times :)

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            N 1 Reply Last reply
            0
            • L leppie

              Natza Mitzi wrote:

              This is strange.

              It is not strange, it's perfect normal behaviour. I suggest you read about the topic a bit more. It has 'bitten' me a few times :)

              xacc.ide - now with TabsToSpaces support
              IronScheme - 1.0 alpha 4a out now (29 May 2008)

              N Offline
              N Offline
              Natza Mitzi
              wrote on last edited by
              #6

              You are correct. :~

              Natza Mitzi

              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