Wednesday 2 June 2010

The state information is invalid for this page and might be corrupted

This is a nice gotcha for load balanced ASP.NET sites:
If you have a dynamically compiled ASP.NET website, and you put objects from a dynamic part into the ViewState, you'll be in for a NASTY surprise when you move to a load-balanced scenario.
Basically, you'll occasionally get exceptions with the message "The state information is invalid for this page and might be corrupted" as the compiled types on the different servers are different.
Either:
  • Move the types you put into ViewState into a compiled assembly (dll for old-schoolers ), or,
  • Only use primitive types (int, byte, string, char, etc) in the ViewState. Enums do not count as primitive types.

No comments: