Share via


ASPCOMPAT related issue in ASP.NET 2.0

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" https://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...

Comments

  • Anonymous
    July 10, 2006
    So, is this a bug or are we to change our session state management, etc. as described above?

  • Anonymous
    July 10, 2006
    The comment has been removed

  • Anonymous
    July 12, 2006
    The comment has been removed

  • Anonymous
    November 13, 2006
    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.

  • Anonymous
    November 13, 2006
    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