Rahul Soni's blog

Never assume the obvious is true!

ASPCOMPAT related issue in ASP.NET 2.0

ASPCOMPAT related issue in ASP.NET 2.0

  • Comments 5

Recently, I saw a very interesting issue. Thought, I must share...

There were two pages in an application. In the 2nd one (page2.aspx), aspcompat was equal to true. In the first one, we did something with a lot of objects, "stored it in the session", went to page2.aspx and splat!! The following error was thrown up. The weird thing was that, it worked in ASP.NET 1.1, but it simply refused to work in ASP.NET 2.0.

Server Error in '/vs2005 Test web application' Application.
--------------------------------------------------------------------------------
An error was encountered while calling OnStartPage in ASP compatibility mode.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: An error was encountered while calling OnStartPage in ASP compatibility mode.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): An error was encountered while calling OnStartPage in ASP compatibility mode.]
System.Web.Util.AspCompatApplicationStep.OnPageStartSessionObjects() +780634
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1996
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

We were quite confused about how to troubleshoot the issue. So, we started with isolation of the objects stored in the session in that page which could be causing it. Very soon we realized that it was because of a custom dataset object that was stored in session. As soon as we commented the line (which added the problematic object to the Session) out, we found that the issue was resolved. Now, the question remained that what was wrong with that object???

At that point, I thought of using "StateServer" mode in web.config, instead of "InProc" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfsessionstatesection.asp. As soon as we tried running the application again with the problematic object uncommented, we saw a new error message. I will modify it accordingly because of privacy issues (it doesn't really matter which company's component it was, anyways!!!), but I will give you a glimpse about what the "new" error was...

The constructor to deserialize an object of type 'xxx.yyy.zzz' was not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.Serialization.SerializationException: The constructor to deserialize an object of type 'xxx.yyy.zzz' was not found.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:

[SerializationException: The constructor to deserialize an object of type 'xxx.yyy.zzz' was not found.]    System.Runtime.Serialization.ObjectManager.GetConstructor(Type t, Type[] ctorParams) +2313073    System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context) +99  [SerializationException: The constructor to deserialize an object of type 'xxx.yyy.zzz' was not found.]    System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context) +239    System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder) +44    System.Runtime.Serialization.ObjectManager.DoFixups() +167    System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +203    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +190    System.Web.Util.AltSerialization.ReadValueFromStream(BinaryReader reader) +745    System.Web.SessionState.SessionStateItemCollection.ReadValueFromStreamWithAssert() +54    System.Web.SessionState.SessionStateItemCollection.DeserializeItem(String name, Boolean check) +257    System.Web.SessionState.SessionStateItemCollection.DeserializeItem(Int32 index) +107    System.Web.SessionState.SessionStateItemCollection.get_Item(Int32 index) +20    System.Web.SessionState.HttpSessionStateContainer.get_Item(Int32 index) +10    System.Web.Util.AspCompatApplicationStep.OnPageStartSessionObjects() +80    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1996

As it can be seen the description is much clear and adding the constructor to deserialize the object of type "xxx.yyy.zzz" fixed the aspcompat issue!!

Until next time...

  • So, is this a bug or are we to change our session state management, etc. as described above?
  • I don't know if I should call this a bug. It was an issue with a 3rd party component and I found that using the above methodology we were able to get to the root cause of it. Changing the session state management was just a step to see if the error message changes to something more meaningful and it did, which helped us to fix the underlying issue!!
  • We've had some success (haven't covered all of our code yet) simply wrapping the dataset in a simple class.  i.e., instead of sticking the dataset directly into the session, stick a simple object reference into the session that contains your dataset.  e.g.

    public class Foo
    {
       private DataSet ds;
       public Foo(DataSet ds)
       {
           this.ds=ds;
       }
       public DataSet TheDataSet
       {
           get{return this.ds;}
       }
    }

    Stick a Foo instance in the session rather than the dataset then fish the dataset out via Foo's TheDataSet property.
  • This sounds like the problem I am having.  However, I am unfamiliar with serialization.  Can you give me example code that you used to add the constructor to deserialize?  I have no idea how to go about this.

  • Well, the code was added by the 3rd party, so even I am not aware of it. Basically, try doing this...

    1. Create a brand new page on which you are facing that problem (because we have to mess a lot with the new page).

    2. Try removing everything from Session/Cache and see if the issue happens

    3. If the issue doesn't happen after removing the variables, you just need to find that culprit object and do the needful.

    Can take a little bit of time, but this is how we fixed it. Trial and error. And in my case, the customer was really smart. All I did was suggest the same to him and he was able to find out which *exact* object was causing the problems!!

    Hope that helps...

    Rahul

Page 1 of 1 (5 items)
Leave a Comment
  • Please add 1 and 7 and type the answer here:
  • Post