We are using ASP.NET viewstate to store our own objects (ie, not just primitive types). Each time we do a build, the build number is incremented. The issue we are trying to work around is during a server update:
- User loads the page
- We deploy a new build of the web application
User causes a postback on the same page, and an exception is thrown:
- HttpException: The state information is invalid for this page and might be corrupted.
- ViewStateException: Invalid viewstate.
- ArgumentException: The serialized data is invalid.
- FileLoadException: Could not load file or assembly '[our assembly], Version=[our new version], Culture=neutral, PublicKeyToken=...' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference
I understand why it's happening - the ViewState was serialized with the previous version of the class, and is then trying to deserialize with the new version and .NET serialization doesn't support that.
We've considered creating a custom PageStatePersister and using JSON (and then encrypting it) to serialize/deserialize instead, since the data members are almost always compatible between builds.
Any other ideas?