Episerver Scheduled Job fails (scheduler service)

Posted by Igor on Stack Overflow See other posts from Stack Overflow or by Igor
Published on 2013-06-26T16:19:27Z Indexed on 2013/06/26 16:21 UTC
Read the original article Hit count: 445

Filed under:

Our scheduled jobs started failing since yesterday with the following error message:
CustomUpdate.Execute - System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Security.Roles.GetRolesForUser(String username) at EPiServer.Security.PrincipalInfo.CreatePrincipal(String username)

The scheduled job uses anonymous execution and logs in programmatically using the following call:

if (PrincipalInfo.CurrentPrincipal.Identity.Name == string.Empty)
{
     PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal(ApplicationSettings.ScheduledJobUsername);
}

I have put in some more logging around PrincipalInfo.CreatePrincipal call which is in Episerver.Security and noticed that PrincipalInfo.CreatePrincipal calls System.Web.Security.Roles.GetRolesForUser(username) and Roles.GetRolesForUser(username) returns an empty string array. There were no changes code wise or on the server (updates, etc). I checked that the user name used to run the task is in the database and has roles associated with it. I checked that applicationname is set up correctly and is associated with the user If i run the job manually using the same user it executes with no issues (i know there is a difference between running the job manually and using the scheduler) I also tried creating a new user, that didn’t work either. Has anyone come across the same or similar issue? Any thoughts how to resolve this issue?

© Stack Overflow or respective owner

Related posts about episerver