This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16577|Reply: 1

[ASP.NET] Session states cannot be serialized. In "StateServer" or "SQLServer" mode...

[Copy link]
Posted on 11/18/2017 9:37:45 PM | | | |
Session states cannot be serialized. In "StateServer" or "SQLServer" mode, ASP.NET will serialize session state objects, so non-serializable objects or MarshalByRef objects are not allowed. The same restrictions apply if the custom session state store performs similar serialization in "Custom" mode.        



Solution:

Variables cannot be serialized when assigning a Session, so try adding [Serializable] to the Class. Problem solving

[Serializable]
public class MyClass
{
.......
}

Let's talk about [Serializable], which is used to inform the compiler that the class can be serialized

Serialization refers to the process of storing the state of an object instance to a storage medium. In this process, the public and private fields of the object and the name of the class (including the assembly in which the class resides) are converted into a bytestream before writing the bytestream to the datastream. When the object is subsequently deserialized, an identical copy of the original object is created.
When implementing serialization mechanisms in an object-oriented environment, there must be some trade-offs between ease of use and flexibility. As long as you have enough control over this process, you can make it largely automatic. For example, simple binary serialization doesn't suffice, or there is a need to determine which fields in a class need to be serialized for a specific reason. The following sections will explore the reliable serialization mechanisms provided by the .NET framework and highlight some of the important features that allow you to customize the serialization process to your needs.





Previous:ASP.NET StateServer that stores the Session
Next:sqlserver how to copy one table for another
 Landlord| Posted on 11/19/2017 4:19:48 PM |
For some objects that inherit from MarshalByRef, such as DbTransation objects, they cannot be serialized. Therefore, you cannot use Session to store objects that inherit the MarshalByRef type.
The workaround is to use the Cache and SessionID to emulate the Session. The Cache class can cache any type of object.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com