Hi guys,
I'm not sure whether this is an NHibernate error, but I'm totally stumped and Google hasn't been able to provide an answer. Perhaps some of you have seen it before as I imagine what I'm trying to do is quite common...?
So, I've got a .NET MVC2 website (C#). When a user logs in, I persist the User object I get from NHibernate to the web-session. (I Evict it from the NHibernate session first to be on the safe side.)
Here is the relevant code for persisting the user following on log on:
Code:
var userRepository = DependencyFactory.Get<IUserRepository>();
var user = userRepository.GetByUserNameAndPassword(userName, password);
userRepository.Evict(user);
var statePersister = DependencyFactory.Get<IStatePersister>();
statePersister.State.CurrentUser = user;
...as you can see I'm using a simple repository pattern to wrap the NHibernate stuff, and I'm also using a state persister pattern to allow all session variables to be stored in a single Serializable strongly typed class.
The important bit from the persister is as follows:
Code:
public State State
{
get
{
lock (stateLock)
{
var state = HttpContext.Current.Session[sessionKey] as State;
if (state == null)
{
state = new State();
HttpContext.Current.Session[sessionKey] = state;
}
return state;
}
}
}
If I change my user object and then try and access the State class from the state persister, I get the following error
"Cannot create an abstract class."
...when I get to the line:
Code:
var state = HttpContext.Current.Session[sessionKey] as State;
Any one got any clues where to start looking with this? Any help gratefully received!
Thanks in advance,
Steve.