mini-profiler nullreferenceexception

2019-06-22 01:11发布

问题:

When a stored procedure I'm running executes mini-profiler throws a null reference and causes my application to stop. In this instance the SP doesn't return anything.

Here is the stacktrace:

   at MvcMiniProfiler.MiniProfiler.AddSqlTiming(SqlTiming stats) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\MiniProfiler.cs:line 274
   at MvcMiniProfiler.SqlTiming..ctor(DbCommand command, ExecuteType type, MiniProfiler profiler) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\SqlTiming.cs:line 137
   at MvcMiniProfiler.SqlProfiler.ExecuteStartImpl(DbCommand command, ExecuteType type) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\SqlProfiler.cs:line 39
   at MvcMiniProfiler.SqlProfilerExtensions.ExecuteStart(SqlProfiler sqlProfiler, DbCommand command, ExecuteType type) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\SqlProfiler.cs:line 93
   at MvcMiniProfiler.MiniProfiler.MvcMiniProfiler.Data.IDbProfiler.ExecuteStart(DbCommand profiledDbCommand, ExecuteType executeType) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\MiniProfiler.IDbProfiler.cs:line 14
   at MvcMiniProfiler.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\Data\ProfiledDbCommand.cs:line 158
   at System.Data.Common.DbCommand.ExecuteReader()
   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
   at System.Data.Linq.DataContext.ExecuteMethodCall(Object instance, MethodInfo methodInfo, Object[] parameters)
   at NetINFO.NetINFODataContext.usp_SRM_GetPlansByType(Nullable`1 sRM_ID, Nullable`1 sRM_PlanTypeID) in C:\Code\netinfo\NetInfo.Web\App_Data\NetINFO.designer.cs:line 1949
   at NetINFO.NetCMG.SRM.GetSRMPlans(Int32 pPlanType) in C:\Code\netinfo\NetInfo.Web\pages\NetCMG\classes\SRM.cs:line 673
   at NetINFO.NetCMG.SRM.Validate() in C:\Code\netinfo\NetInfo.Web\pages\NetCMG\classes\SRM.cs:line 540
   at NetCMG.Controls.TicketErrorsCtl.ValidateTicket(SRM Ticket) in C:\Code\netinfo\NetInfo.Web\pages\NetCMG\Controls\TicketErrorsCtl.ascx.cs:line 29
   at NetCMG.Controls.TicketErrorsCtl.Page_Load(Object sender, EventArgs e) in C:\Code\netinfo\NetInfo.Web\pages\NetCMG\Controls\TicketErrorsCtl.ascx.cs:line 16
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

回答1:

I finally figured out the solution to my question above. The error was happening on a legacy webforms application that was using sql data source for the grid. The sql datasource was using the 'ProviderName' property. Once I removed this property everything started working.



回答2:

Had the same problem: NRE from application start. Exception occures at MvcMiniProfiler.MiniProfiler.AddSqlTiming(SqlTiming stats)

Problem reason: database call in Application_AuthenticateRequest()

Problem solution: MiniProfiler.Start(); moved to the end of Application_AuthenticateRequest() method.