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
error deserializing object from previous application version
Started by elloco999, Jul 10 2009 12:46 AM
3 replies to this topic
#1
Posted 10 July 2009 - 12:46 AM
|
|
|
#2
Posted 15 July 2009 - 03:51 PM
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
Posted 16 July 2009 - 02:15 AM
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).
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
Posted 16 July 2009 - 01:21 PM
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.
Thanks for posting your answer back on the forum.


Sign In
Create Account

Back to top









