SerializationException with Custom GenericIdentiy?

I'm trying to implement my own implementation of GenericIdentity, but keep getting the following error when trying to load views (I use asp.net MVC):

 System.Runtime.Serialization.SerializationException was unhandled 
 by user code Message="Type is not resolved for member 
 'OpenIDExtendedIdentity,Training.Web, Version=1.0.0.0, 
 Culture=neutral, PublicKeyToken=null'."
      Source="WebDev.WebHost"

I ended up with the following class:

[Serializable]
    public class OpenIDExtendedIdentity : GenericIdentity {
        private string _nickName;
        private int _userId;

        public OpenIDExtendedIdentity(String name, string nickName, int userId)
            : base(name, "OpenID") {
            _nickName = nickName;
            _userId = userId;
        }
        public string NickName {
            get { return _nickName; }
        }

        public  int UserID {
            get { return _userId; }
        }
    }

In my Global.asax, I read the serialized cookie value in the memory stream and then used it to create my OpenIDEEXendedIdentity object. I ended this attempt at solving after countless attempts of all kinds. It works correctly until the moment when it tries to display the views.

What I'm basically trying to achieve is the ability to do the following (when using the default role manager from asp.net):

User.Identity.UserID
User.Identity.NickName
... etc.

, . Cassini, , , - , .

+5
3

, , .

.

, Cassini, , MarshalByRefObject:

[Serializable]
public class MyUser : MarshalByRefObject, IIdentity
{
    public int UserId ... 

, , GenericIdentity, IIdentity, GenericIdentity, , IIdentity.

+3

, VisualStudio ( -), IIS Express VS2012 IIS, . : fooobar.com/questions/637836/...

0

"baggadonuts" . .

[Serializable]
public class StubIdentity : IIdentity, ISerializable



public void GetObjectData(SerializationInfo info, StreamingContext context)
{
    if (context.State == StreamingContextStates.CrossAppDomain)
    {
        GenericIdentity gIdent = new GenericIdentity(this.Name, this.AuthenticationType);
        info.SetType(gIdent.GetType());

        System.Reflection.MemberInfo[] serializableMembers;
        object[] serializableValues;

        serializableMembers = FormatterServices.GetSerializableMembers(gIdent.GetType());
        serializableValues = FormatterServices.GetObjectData(gIdent, serializableMembers);

        for (int i = 0; i < serializableMembers.Length; i++)
        {
            info.AddValue(serializableMembers[i].Name, serializableValues[i]);
        }
    }
    else
    {
        throw new InvalidOperationException("Serialization not supported");
    }
}
0

All Articles