Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MiniProfiler NullReferenceException in SqlServerStorage.LoadInBatch() function due to client timings

I'm getting the following exception when I click on the share link for an individual profile. I'm using the latest version from NuGet, 2.0.1.

The Exception:

System.NullReferenceException: Object reference not set to an instance of an object.
   at StackExchange.Profiling.Storage.SqlServerStorage.LoadInBatch(DbConnection conn, Object idParameter) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\Storage\SqlServerStorage.cs:line 348    
   at StackExchange.Profiling.Storage.SqlServerStorage.Load(Guid id) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\Storage\SqlServerStorage.cs:line 297 
   at StackExchange.Profiling.UI.MiniProfilerHandler.Results(HttpContext context) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\UI\MiniProfilerHandler.cs:line 314 
   at StackExchange.Profiling.UI.MiniProfilerHandler.ProcessRequest(HttpContext context) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\UI\MiniProfilerHandler.cs:line 188 
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

The code:

I found what I think is the source of the null reference in the code here:

ClientTimings clientTimings = null;
if (clientTimingList.Count > 0)
{
    clientTimings.Timings = clientTimingList;
}

Am I missing something, or is that always going to throw an exception when there are entries in the clientTimingList?

Workarounds:

  • I thought maybe if I disabled batching, I wouldn't run the LoadInBatch function, but LoadIndividually has the same issue.

  • I looked for a way to disable client timings, but couldn't find a setting for it.

  • Maybe I could set a trigger in the database to delete the rows, but that seems a little extreme.

If I get the time, I'll get the code and submit a pull request. I wanted to make sure I wasn't missing anything obvious first.

like image 592
David Hogue Avatar asked Nov 04 '22 01:11

David Hogue


1 Answers

Looks like it was a bug. I've added a ticket on github and a pull request to fix it: https://github.com/SamSaffron/MiniProfiler/pull/40

The new code looks like this:

if (clientTimingList.Count > 0)
{
    clientTimings = new ClientTimings();
    clientTimings.Timings = clientTimingList;
}
like image 84
David Hogue Avatar answered Dec 01 '22 17:12

David Hogue