I seem to have stumbled across a solution. If I declare my
ISessionState
interface with the
out
keyword, like this...
public interface ISessionState<out S> where S : ISession
...then the compiler is happy and the cast works.
I would still very much appreciate comments on this, since I'm not sure exactly what I have done.