SaaS CMS has officially launched! Learn more now.

Episerver Scheduled Job fails (scheduler service)


Hi all,

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? Thanks in advance.

Jun 26, 2013 18:16

Do you get the same behaviour if you replace ApplicationSettings.ScheduledJobUsername with the username you are logged in as (that works when you run the job manually)?

Jun 26, 2013 19:10

Yes, same behaviour. Actually its with any user.

Jun 26, 2013 20:48
Jun 27, 2013 8:44

Hi Per, thanks for that post. That is exactly what i did to work around the problem, however, it is not ideal and it is still not clear why the other approach is not working. 

Jun 27, 2013 9:36

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. 

Jul 03, 2013 14:06
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.