Glimpse / Glimpse.Prototype

Glimpse v2 prototype
MIT License
184 stars 44 forks source link

System.NullReferenceException: Object reference not set to an instance of an object. #125

Closed ousiax closed 8 years ago

ousiax commented 8 years ago

Question: How to handle this exception ?

System.NullReferenceException: Object reference not set to an instance of an object.
   at Glimpse.Common.DefaultGlimpseContextAccessor.get_RequestId()
   at Glimpse.Agent.Razor.ScriptInjector..ctor(IGlimpseContextAccessor context, IResourceOptionsProvider resourceOptionsProvider)
   at lambda_method(Closure , IServiceProvider , Object[] )
   at Microsoft.AspNet.Mvc.Infrastructure.DefaultTypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType)
   at Microsoft.AspNet.Mvc.Razor.RazorPage.CreateTagHelper[TTagHelper]()
   at Asp.ASPV__Views_Shared__Layout_cshtml.<ExecuteAsync>d__23.MoveNext() in /Views/Shared/_Layout.cshtml:line 13
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNet.Mvc.Razor.RazorView.<RenderPageAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ousiax commented 8 years ago

HI,

It just happens when I publish my web application and host it on IIS.

And, finally, I found the magic,

namespace Glimpse.Agent.Internal.Inspectors
{
    public partial class WebDiagnosticsInspector
    {
        [DiagnosticName("Microsoft.AspNet.Hosting.BeginRequest")]
        public void OnBeginRequest(HttpContext httpContext)
        {
            // TODO: Not sure if this is where this should live but it's the earlist hook point we have
            _contextData.Value = new MessageContext { Id = Guid.NewGuid(), Type = "Request" };

            var request = httpContext.Request;