Tuesday, April 08, 2008

Profile Serialization Hell (similar to Dll Hell)

I recently came across the problem of modifying the interface to one of the classes that was contained within a custom ASP.NET 2.0 profile class. The worry was that if the property name via which that particular property is accessed gets changed, the profile will break. The consequence of this breakage would have been that if the user is logged in while the code gets deployed (I know that code deployment should, in most cases, be deployed after hours) the serialized profile object in the SQLProfileProvider would not match that of the new deployed object and it would error out or the site would not function properly. Here is an interesting insight.

Properties are just getter/setter methods in .NET, i.e. I had nothing to worry about breaking the compatibility. I could have the name of the property itself. The culprit is when the private variable name that gets serialized and deserialized when reading the profile object stored in the database. If you change the name of this private variable, it breaks!

The point is that if you don't change the variable name, everything should be fine, even if you add new properties and their corresponding serializable variables. Note that removing a variable will definitely break the compatibility.

0 comments: