adamfoneil / Dapper.CX

A Crud library based on Dapper
MIT License
8 stars 1 forks source link

Need to diagnose a difficult null ref exception #41

Closed adamfoneil closed 3 years ago

adamfoneil commented 3 years ago

So, when I deploy my new Blazor app to Azure, there's a null ref exception when the DapperCX service is resolved. This doesn't happen locally. I get some stack trace info that is leading me to this extension method

image

There are several possible fail points in here, but my thinking is that it's a problem within the IOnboardUser service. So, I want to inject some logging to see what it's doing. This involves changing the AddSessionUser ext method to be able to add an ILogger to it.

adamfoneil commented 3 years ago

By inlining these service methods into the main app, I can start to get line number diagnostic info. This led me to the specific null ref issue.

image

adamfoneil commented 3 years ago

The root issue turns out to be inconsistent availability of HttpContext.User -- it's present when running locally, but intermittently absent when published. Yes, that's every bit as maddening as it sounds. I ended up not needing the IUserAccessor interface, and I also removed ISession use, but I think I can bring it back.

adamfoneil commented 3 years ago

I ended up making my own ISession object that reads/writes Json in App_Data. I also started using AuthenticationStateProvider instead of HttpContextAccessor, and this seems to be better. I'm also going to remove all Session artifacts from the AspNetCore project because they just don't need to be there. It makes more sense to let applications figure out their own approach here. All I need to do is provide a delegate that apps can use to decide how they want to get TUser.