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

三世轮回 提交于 2019-12-12 11:03:52

问题


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.


回答1:


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;
}


来源:https://stackoverflow.com/questions/10144061/miniprofiler-nullreferenceexception-in-sqlserverstorage-loadinbatch-function-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!