London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

ServiceLocator.Current.GetInstance<FOO>() returns null, crashing AlloyDemo

Vote:
 

Hi all,

I'm currently running through the CMS training content with AlloyDemo, and I'm currently getting a server error for this line:

Object reference not set to an instance of an object.

AdministratorRegistrationPage.cs

Line 57: var res = provider.GetAllUsers(0, 1, out totalUsers);


In addition, I'm getting a similar error for other classes when commenting out Administrator Registration. This happens whenever provider is null, given by the line:

var provider = ServiceLocator.Current.GetInstance<UIUserProvider>();

Does anybody know why ServiceLocator would return null? This happened sort of out of the blue. Everything worked fine on February 6th.

Thank you!
#216535
Edited, Feb 08, 2020 18:35
TecroNet - Feb 08, 2020 18:41
Does anybody know why ServiceLocator would return null? This happened sort of out of the blue. Everything worked fine on February 6th.
Vote:
 

There is a line there that enables .net identity for Episerver. My best guess is that you accidentally removed that. That would cause an error like you described.

#216538
Feb 08, 2020 18:50
Vote:
 

Make sure that you still have AddCmsAspNetIdentity called in your code. This is where it registers UIUserProvider

As a side note, you should try to use constructor injection instead of ServiceLocator

#216556
Feb 10, 2020 8:12
valdis - Feb 10, 2020 15:18
+1 ;)
Alex - Feb 10, 2020 15:38
Thanks! I must have absentmindedly CTRL-X'ed the line, like Daniel mentioned as well.
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.