Dashboard fails on startup every time, even with new/empty database. Used to work though

Tags: #<Tag:0x00007f185835c880>

I had previously configured Hangfire with the Dashboard and had recurring jobs working. As I started to move from a hello world POC to a more robust ‘host’ and ensuring it was deployment ready I’ve touched & tweaked things along the way, but I believe what I have is still basically equivalent and no radical differences in the basic ASP web app startup.

Now when I try to run, I can see the recurring jobs get auto-registered by my code and they appear to be running. The dashboard consistently fails though. One difference is that I’ve added Razor support and previously only had MVC enabled (iirc, need to check history). I’ve tried not enabling Razor to see if that was the difference and there was no change in the outcome or error itself.

I’m chasing this one and not seeing anything obvious. I’m stilly fairly new to the newer .NET Core stuff and especially the ASP side with Mvc/Razor. It worked before so there’s got to be some minor thing I’m just not realizing has bearing on this.

In the interim if anyone can assist, it’d be appreciated as I’m trying to demonstrate Hangfire in a POC and make the case for using it.

*NullReferenceException: Object reference not set to an instance of an object.*
*    Hangfire.Dashboard.Pages.LayoutPage.Execute()*
*    Hangfire.Dashboard.RazorPage.TransformText(string body)*
*    Hangfire.Dashboard.RazorPage.TransformText(string body)*
*    Hangfire.Dashboard.RazorPage.ToString()*
*    Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)*
*    Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)*
*    Microsoft.AspNetCore.Builder.Extensions.UsePathBaseMiddleware.Invoke(HttpContext context)*
*    Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)*
*    Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)*

*    Show raw exception details*
*    System.NullReferenceException: Object reference not set to an instance of an object.*
*       at Hangfire.Dashboard.Pages.LayoutPage.Execute()*
*       at Hangfire.Dashboard.RazorPage.TransformText(String body)*
*       at Hangfire.Dashboard.RazorPage.TransformText(String body)*
*       at Hangfire.Dashboard.RazorPage.ToString()*
*       at Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)*
*       at Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)*
*       at Microsoft.AspNetCore.Builder.Extensions.UsePathBaseMiddleware.Invoke(HttpContext context)*
*       at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)*
*       at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)*

For anyone that stumbles across this later, the root cause ended up being that I was moving some of my configuration into the actual appsettings.json file and in this case the name “Dashboard Title” in my json wasn’t matching the class member name of “DashboardTitle”.

So what was being passed was a null reference; The call-stack/error message wasn’t helpful and I only happened to notice this. Seems like a little guardrail/validation in that code path could save a lot of headaches tracking things down. I put a validation in place for my code to at least handle it there.