Microsoft KB Archive/922621

= 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: &quot;A deserialization error occurred&quot; =

Article ID: 922621

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 2.0
 * Microsoft ASP.NET 2.0

-



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 &quot;Applies to&quot; section.

Keywords: kbtshoot kbbug kbnofix KB922621

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.