Upgrade to v5.11 breaks AppHost.Container.RegisterValidators

System.NullReferenceException: ‘Object reference not set to an instance of an object.’ exception thrown when trying to register validators during AppHost setup using AppHost.Container.RegisterValidators(typeof(BackendServices).Assembly);

Worked using previous version of ServiceStack 5.10.4

  at ServiceStack.Validators.RegisterPropertyRulesFor(Type type) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Validators.cs:line 272
       at ServiceStack.Validation.ValidationExtensions.RegisterValidator(Container container, Type validator, ReuseScope scope) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Validation\ValidationFeature.cs:line 416
       at ServiceStack.Validation.ValidationExtensions.RegisterValidators(Container container, ReuseScope scope, Assembly[] assemblies) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Validation\ValidationFeature.cs:line 385
       at ServiceStack.Validation.ValidationExtensions.RegisterValidators(Container container, Assembly[] assemblies) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\Validation\ValidationFeature.cs:line 377
       at Tests.AppHostSetup..ctor() in C:\Tests\AppHostSetup.cs:line 171

Any assistance appreciated.
Thanks,
John

Can you try registering it inside the AppHost Configure() method instead of from the AppHost singleton, it’s not clear the AppHost is properly initialized before you’re trying to register the validators.

Unfortunately the StackTrace doesn’t reference the line with the NRE:

Can you try step into debugging to find out what’s null.

Step in, HostContext.AppHost is null

   public static bool RegisterPropertyRulesFor(Type type)
  {
                var container = HostContext.AppHost.Container;  
                ....
  }

OK don’t use the singleton for configuring the AppHost, register the validators in AppHost.Configure(Container container) i.e. where AppHost configuration should be done.

If you’re trying to configure it before then, the AppHost will not be properly initialized.

Thanks, works when reorganised to use AppHost.Configure. Odd that it worked with the prior version but ok now.

Due when support for Declarative Nested Validators were added which needed access to the IOC that’s available after the AppHost has been pre-initialized.

It’s expected for all AppHost Configuration to occur within AppHost.Configure() or in the Modular Startup classes, additional functionality can be added at anytime to require access to the AppHost which will result in a similar runtime error, so if you have any other AppHost configuration running before AppHost Confgure() it should also be moved.

Appreciate the quick response and will have a look at nested validators. I’ve re-organised into AppHost.Configure().