{"action":"created","issue":{"url":"https://api.github.com/repos/ServiceStack/Issues/issues/256","labels_url":"https://api.github.com/repos/ServiceStack/Issues/issues/256/labels{/name}","comments_url":"https://api.github.com/repos/ServiceStack/Issues/issues/256/comments","events_url":"https://api.github.com/repos/ServiceStack/Issues/issues/256/events","html_url":"https://github.com/ServiceStack/Issues/issues/256","id":62131408,"number":256,"title":"Custom user session is broken since v.4.36 ","user":{"login":"uranium62","id":1567570,"avatar_url":"https://avatars.githubusercontent.com/u/1567570?v=3","gravatar_id":"","url":"https://api.github.com/users/uranium62","html_url":"https://github.com/uranium62","followers_url":"https://api.github.com/users/uranium62/followers","following_url":"https://api.github.com/users/uranium62/following{/other_user}","gists_url":"https://api.github.com/users/uranium62/gists{/gist_id}","starred_url":"https://api.github.com/users/uranium62/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uranium62/subscriptions","organizations_url":"https://api.github.com/users/uranium62/orgs","repos_url":"https://api.github.com/users/uranium62/repos","events_url":"https://api.github.com/users/uranium62/events{/privacy}","received_events_url":"https://api.github.com/users/uranium62/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-16T16:20:45Z","updated_at":"2015-03-16T16:26:10Z","closed_at":null,"body":"**Problem:**\r\n```\r\npublic class MyService : Service \r\n{\r\n    public object Get(MyRequest request)\r\n    {\r\n        var userSession = this.SessionAs<CustomUserSession>();\r\n    }\r\n}\r\n```\r\n\r\n**Exception:**\r\nUnable to cast object of type 'ServiceStack.AuthUserSession' to type 'My.Web.CustomUserSession'\r\n\r\n**Reason:**\r\nIn the method of the function *SessionFeature.GetOrCreateSession()* is a string *(T)((object)SessionFeature.CreateNewSession(httpReq, sessionId));* that cast to an incorrect object type\r\n\r\n```\r\npublic static IAuthSession CreateNewSession(IRequest httpReq, string sessionId)\r\n{\r\n\t\t\tIAuthSession authSession = AuthenticateService.CurrentSessionFactory();\r\n\t\t\tauthSession.Id = (sessionId ?? SessionFeature.CreateSessionIds(httpReq, null));\r\n\t\t\tauthSession.CreatedAt = (authSession.LastModified = DateTime.UtcNow);\r\n\t\t\tauthSession.OnCreated(httpReq);\r\n\t\t\tIAuthEvents authEvents = HostContext.TryResolve<IAuthEvents>();\r\n\t\t\tif (authEvents != null)\r\n\t\t\t{\r\n\t\t\t\tauthEvents.OnCreated(httpReq, authSession);\r\n\t\t\t}\r\n\t\t\treturn authSession;\r\n}\r\n```\r\n*AuthenticateService.CurrentSessionFactory();* always returns an object of type *AuthUserSession*\r\n\r\nI think need to change to the service locator\r\n```\r\n IAuthSession authSession = AppHost.Instance.TryResolve<IAuthSession >()\r\n```\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ServiceStack/Issues/issues/comments/81775928","html_url":"https://github.com/ServiceStack/Issues/issues/256#issuecomment-81775928","issue_url":"https://api.github.com/repos/ServiceStack/Issues/issues/256","id":81775928,"user":{"login":"mythz","id":89361,"avatar_url":"https://avatars.githubusercontent.com/u/89361?v=3","gravatar_id":"","url":"https://api.github.com/users/mythz","html_url":"https://github.com/mythz","followers_url":"https://api.github.com/users/mythz/followers","following_url":"https://api.github.com/users/mythz/following{/other_user}","gists_url":"https://api.github.com/users/mythz/gists{/gist_id}","starred_url":"https://api.github.com/users/mythz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mythz/subscriptions","organizations_url":"https://api.github.com/users/mythz/orgs","repos_url":"https://api.github.com/users/mythz/repos","events_url":"https://api.github.com/users/mythz/events{/privacy}","received_events_url":"https://api.github.com/users/mythz/received_events","type":"User","site_admin":false},"created_at":"2015-03-16T16:26:10Z","updated_at":"2015-03-16T16:26:10Z","body":"Please provide the source code you're using to register the AuthFeature and the type definition of `CustomUserSession`."}}