Jump to content

error deserializing object from previous application version

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
elloco999

elloco999

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,

I have signed my application, but now, when I make a new build with a higher assembly version number it can't deserialize an object that was serialized by the previous version.

So my current application is version 1.0.3.12. I serialize an object with this version. Then I increase the version number to 1.0.3.13 and build it. When I try to deserialize the object, I get an error:

Can not load file or assembly MyApp, Version=1.0.3.12, Culture=neutral, PublicKeyToken=d68hjk94t6n716gq or one of it's depedencies. The manifestation of the found assembly doesn't match the assembly reference.

Probably not exactly correct, since I translated it from dutch.

Any help would be greatly appreciated!

Thanks,
Rick

#2
scottk

scottk

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
Can you post the code you are using to serialize/deserialize with, and the class definition of what is being serialized? This should be version and assembly independant... I have a feeling something else is causing the issue.

#3
elloco999

elloco999

    Newbie

  • Members
  • Pip
  • 3 posts
Hi scottk,

I've already solved the problem with help of this MSDN article: msdn.microsoft.com/en-us/magazine/cc188950.aspx (sorry, my post count isn't high enough to post a link...).

When serializing/ deserializing with an unsigned application it is "almost" version independent. I say almost, because it will only work when you haven't made any changes to the object being deserialized that will break the deserializing process. For instance, if your object has a name property and you serialize it, when you try to deserialize it after having removed the name property, it will not work. But as long as there are no errors during the deserialization process, it is version independent.

But when you sign your application, the deserialing process will generate a object with the versionnumber of the old application, and then try to store that in a object with the new versionnumber.
So if I serialized an object with fullname

"MyAssembly.MyClass, MyAssembly, Version=1.0.3.12, Culture=neutral, PublicKeyToken=null"

and you try to deserialize it as an object with fullname

"MyAssembly.MyClass, MyAssembly, Version=1.0.3.13, Culture=neutral, PublicKeyToken=d68hjk94t6n716gq",

it won't work. To circumvent this, I have written my own SerializationBinder, as explained in the last part of the MSDN article. I simply replace the versionnumber with the executing assembly's versionnumber and do the same for the PublicKeyToken (the culture is always neutral for me).

#4
scottk

scottk

    Learning Programmer

  • Members
  • PipPipPip
  • 35 posts
Interesting, I did not know that. I suppose it is a mixed blessing that I don't ship signed applications.

Thanks for posting your answer back on the forum.