Question

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?

Was it helpful?

Solution

I have finally found a problem - application pool running with more than one worker processes (in my instance I had two worker processes). Once I set worker processes limit to one everything started to work again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top