1

The Actual Problem and Question:

The web server is throwing a serialization error when I switch the sessionState mode from InProc to StateServer. What do I need to change to make it work correctly?

Technologies:

vb.Net and C# in ASP.Net, IIS7, Framework 4

Details:

We are switching our ASP.Net web site's sessionState mode from InProc to StateServer. This is one change of several we're making to be able to share sessionIDs and session information between 2 web applications on the same server. The server hosting the webs will also be running the ASP.Net State Service service.

When I switch the mode of the sessionState in the web.config file of the main site, I get a server error:

Invalid cast from 'System.Int32' to 'OurCompany.OurApp.Objects.User+enUserType'.

The User class is declared as Serializable, and always has been as we stored the user in the session:

<System.ComponentModel.DesignerCategory("Code"), SerializableAttribute()> Public Class User
    Inherits BaseClass
    Implements System.Runtime.Serialization.ISerializable

I temporarily changed the declaration to:

<Serializable()> Public Class User

in case that would help, but it didn't change anything.

The User class has a Public Enum of enUserType:

Public Enum enUserType
    usrInternal = 1
    usrCustomer
    usrCarrier
    usrSupplier
End Enum

and a Public property:

Public Property UserType() As enUserType
    Get
        Return m_iUserType
    End Get
    Set(ByVal Value As enUserType)
        m_iUserType = Value
    End Set
End Property

These aren't specifically marked as Serializable, but from what I read, they shouldn't need to be. Just in case, I tested it with them being marked Serializable, and it didn't fix the problem.

If I switch the sessionState mode back to InProc, it works fine. I was under the impression that if your objects serialize correctly for InProc, they should also work for StateServer. I'm basing this assumption off of other peoples' questions and answers I've read, but it may be wrong.

In case it's my web.config configured improperly, this is what the sessionState tag looks like:

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false"/>

I've started the ASP.Net State Service server on the web server and I checked the configuration in the registry to make sure that it is listening on the default port of 42424 and it is.

If there are any more details you think will be relevant, please let me know and I'll add them in.

Thanks,

-BEP

Additional Information

After looking at some other articles suggested by EdSF, I added the XmlAttribute XmlEnum but that didn't help. I tried some other suggestions and didn't get any different results.

This made me throw out some assumptions on where the issue was and I found a place in the class code where some conversions on the serialized information were happening and that's where the problem was.

bepnewt
  • 29
  • 2
  • You're trying to serialize Enum to int (the exception). See if [this SO thread](http://stackoverflow.com/questions/506368/how-do-i-serialize-an-enum-value-as-an-int) helps. – EdSF Apr 13 '12 at 03:48
  • @EdSF Thanks. Having me try things in the article you linked made me realize I was trying to fix the wrong thing in the code. – bepnewt Apr 13 '12 at 15:39

0 Answers0