Mono Breaks Your Viewstate

Note: this entry has moved.

There is a notorious difference in the logic used by the viewstate serializer when handling non-optimized types that may cause your code to break when running under Mono’s ASP.NET: they never look for an associated type converter and directly pass any non-optimized type to the BinaryFormatter (ouch!).

 

You may say “ok, that’s just an optimization thing; I will get a larger viewstate and will pay some extra processing cost, but why is my code going to break?

 

Suppose you’ve a Customer type you want to store into viewstate and you’ve coded a CustomerConverter type converter for it:

 

[TypeConverter (typeof (CustomerConverter))]

public class Customer {

}

 

This is all you should need to store an instance of Customer into viewstate.

 

Under Microsoft’s implementation it will run just fine: the serializer will get the associated type converter and use that for serializing the Customer instance.

 

Under Mono’s implementation things will go bad because the serializer doesn’t use a type converter if one is available and directly passes the Customer instance to a BinaryFormatter. Of course the Customer type is not ready to be serialized by the BinaryFormatter (it is not marked with the Serializable attribute, it doesn’t implement the ISerializable interface) and that’s why a SerializationException exception will be thrown.

 

Mono team: this should be really easy to fix and by doing so Mono will be more compatible with Microsoft’s implementation, which I suppose is one of your goals :-)

 

I’ve already filled a bug against the serializer (#59495), let’s see how much luck I get…

 

UPDATE: Within hours after being submitted the bug is now fixed, cool!

 

Published Wednesday, June 02, 2004 6:40 PM by vga
Filed under:

Comments

# re: Mono Breaks Your Viewstate

Wednesday, June 02, 2004 9:06 PM by Gonzalo Paniagua
I've just fixed this in mono CVS and added the test I used while gathering information on this issue to xsp/test directory.

Thanks for filing the bug report.

# re: Mono Breaks Your Viewstate

Thursday, June 03, 2004 11:27 AM by Victor Garcia Aprea
Now, that was fast!. Thanks for getting back.

# Viewstate Serialization, one more time!

Wednesday, June 09, 2004 3:42 PM by TrackBack

Leave a Comment

(required) 
(required) 
(optional)
(required)