Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

ASP.NET and Serialization

Back to Forum: Tech Off
  • User profile image

    I have run into some problems with serialization which I have never seen before. I am aware that multiple methods of serialization exist (binary, XML). 

    My root need is to find something to replace the forms coding of:

    Control.Tag = Object

    with the same logic in the world of ASP.NET.  My plan of attack was to serialize the object and put that value in the "Value" of the related ASP.NET control.  Thus when the user selects the given ASP.NET control you get a Serialized value denoting the object selected.

    I first tried to use Binary Formatted Serialization however this proved unreliable as this method serialized both private and public properities.  This caused conflicts with items which were not serializable.

    My project in question contains a series of webpages along with several datalayer business objects.  One of the the business objects has a method for serialization which has proven reliable for years.

    A method exists which serializes via:

    String SerialXML = SerialXML.Serialize<T>(ObjectValue);

    Deserialization occurs via:

    T ObjectValue = SerialXML.Deserialize<T>(SerialXML);


    The problems I am seeing appear to be two fold.  Objects created on a given webpages code behind page cannot be serialized/deserialized by the business layer.  I get errors messages which imply that type "A" cannot be cast as "B" even though they are the same object.  The location the objects were created seems to be the source of the problem.  By this I mean that if Object "A" is created on page "X" and object "B" is created inside the business layer dll "Y", they are not considered to be the same type despite the fact that they are.

    My second problem consists of ENUM's.  Several of the business layer objects have ENUM's which have previously serialized without issue.  When run within the ASP.NET world these values suddenly appear to be non-serializable.  I get error messages which imply that the values are either duplicate values, which is incorrect, or that they could not be reflected.

    Can anyone give me some suggestions on ways to overcome this serialization trouble?  I would hate to have to write custom serialization/deserialization logic for each business object as there are hundreds of such objects.  I suspect I am missing something obvious.



  • User profile image

    I've seen the casting issue before. It seems to be something about the way the .Net runtime handles types from assemblies other than the calling assembly. As far as I am aware the XmlSerializer doesn't appear to be affected by this shortcoming, but the SOAP and Binary formatters are. Also keep in mind that Binary and SOAP serialisation require some reflection permissions not normally granted under medium trust and may cause you problems on the server (the XmlSerializer only serialises public fields, but may still have some permissions issues).

    If you're going to use XML in the value of an HTTP form field, you're going to want to encode it using HttpUtility.

    Generally speaking, I'd question your method and advise you to investigate some ASP.Net MVC tutorials, but without knowing more details I'll bite my tongue.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.