Microsoft Knowledge Base Email Alertz

BUG: Error message in the Web server's event log when you try to deserialize data that is associated with a data type that is defined in the ASP.NET 2.0 code-behind file: A deserialization error occurred

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 922621 - Last Review: December 3, 2007 - Revision: 1.3

BUG: Error message in the Web server's event log when you try to deserialize data that is associated with a data type that is defined in the ASP.NET 2.0 code-behind file: "A deserialization error occurred"

SYMPTOMS

Consider the following scenario:
  • You create a user control that uses the Microsoft .NET Framework 2.0.
  • The user control uses a Microsoft ASP.NET 2.0 code-behind file.
  • The ASP.NET 2.0 code-behind file defines a data type.
  • You try to deserialize data that is associated with the data type.
In this scenario, you may receive an error message in the Web server's event log that resembles the following:
Event code: 3011
Event message: A deserialization error occurred inside of ObjectStateFormatter. A property was typed as Type but the Type instance could not be created for 'YourCustomType, App_Web_6wc_5ues, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Event time: 15/05/2006 11:34:59 PM
Event time (UTC): 15/05/2006 3:34:59 AM
Event ID: 7878cf1cb270476f90c4d7f6191ed0ba
Event sequence: 3
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/1/Root-1-12345678901234567
Trust level: Full
Application Virtual Path: /
Application Path: c:\inetpub\wwwroot\
Machine name: SERVER

Process information:
Process ID: 2596
Process name: aspnet_wp.exe
Account name: SERVER\ASPNET

Exception information:
Exception type: FileNotFoundException
Exception message: Could not load file or assembly 'App_Web_6wc_5ues, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Request information:
Request URL: http://localhost/default.aspx
Request path: /
User host address: 127.0.0.1
User:
Is authenticated: False
Authentication Type:
Thread account name: SERVER\ASPNET

Thread information:
Thread ID: 1
Thread account name: SERVER\ASPNET
Is impersonating: False
Stack trace:
at System.RuntimeTypeHandle._GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.RuntimeType.PrivateGetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError) at System.Web.UI.ObjectStateFormatter.DeserializeType(SerializerBinaryReader reader)
This problem occurs if the following conditions are true:
  • You marked public properties on the user control by using the [Personalizable] attribute. Alternatively, you implemented the IPersonalizable interface in the code-behind file to programmatically control which properties on the user control may be serialized and saved as personalization data.
  • The [Personalizable] attribute or the IPersonalizable interface references a data type that was defined in an ASP.NET 2.0 code-behind page or in a user control.
  • The deserialization process works as expected until the user control or the page that contains the data type definition is recompiled by ASP.NET 2.0.

CAUSE

This problem occurs when the user control or the page that contains the data type definition is recompiled by ASP.NET 2.0. Every time that ASP.NET 2.0 recompiles a user control or a page, ASP.NET 2.0 creates a new auto-generated assembly. The error message occurs when the type information that is stored in the personalization data tries to make a reference to the old auto-generated assembly.

WORKAROUND

To work around this problem, define the data types that are used for personalizable properties in one of the following locations:
  • In classes in the App_Code folder
  • In assemblies in the Bin folder
  • In GAC-deployed assemblies

MORE INFORMATION

The following code sample illustrates this problem.
public partial class TestUserControl : System.Web.UI.UserControl
{
    // Define a user data type.
    public enum userEnumDataType
    {
        Oranges = 1,
        Apples = 2,
        Bananas = 3
    };

    // Define a class member that uses the data type, and then assign a default value to it.
    private userEnumDataType myEnumDataType = userEnumDataType.Apples;

    // Define a property that uses the [Personalizable] attribute.
    [Personalizable]
    public userEnumDataType EnumDataType
    {
        get { return myEnumDataType; }
        set { myEnumDataType = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        refreshData(sender, e);
    }

    void refreshData(object sender, EventArgs e)
    {
        Label1.Text = myEnumDataType.ToString();
    }

}

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

APPLIES TO
  • Microsoft .NET Framework 2.0
  • Microsoft ASP.NET 2.0
Keywords: 
kbnofix kbtshoot kbbug KB922621
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate