views:

180

answers:

1

I'm trying to implement my own GenericIdentity implementation but keep receiving the following error when it attempts to load the views (I'm using 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've 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 a cookie's serialized value into a memory stream and then use that to create my OpenIDExtendedIdentity object. I ended up with this attempt at a solution after countless tries of various sorts. It works correctly up until the point where it attempts to render the views.

What I'm essentially attempting to achieve is the ability to do the following (While using the default Role manager from asp.net):

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

I've listed some of the sources I've read in my attempt to get this resolved. Some people have reported a Cassini error, but it seems like others have had success implementing this type of custom functionality - thus a boggling of my mind.

+1  A: 

I'm not sure if this is exactly the same issue, but I've run into the same issue when trying to create my own identity implementation.

This blog solved my problem: http://www.leandrodg.com.ar/blog/2007/12/cassini-serializationexception-type-is-not-resolved-for-member/

It seems that the problem is there's an issue with identity serialization in Cassini, but you can get around it by deriving your class from MarshalByRefObject:

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

You can't inherit from GenericIdentity then, of course, but you can still implement the IIdentity interface that GenericIdentity implements, so you can use the thing in most places that expect an IIdentity at least.

Badjer