Glass.Mapper icon indicating copy to clipboard operation
Glass.Mapper copied to clipboard

System.NullReferenceException at Glass.Mapper.Sc.Web.RequestContext.GetRootItem

Open VigneshJothikumar opened this issue 5 years ago • 4 comments

Hi, I am using Glass mapper version 5.5.28 in Sitecore 9.2 Version I am getting below error in azure hosted environment can you please help on this.

assembly : Glass.Mapper.Sc, Version=5.5.28.0, Culture=neutral, PublicKeyToken=null method : Glass.Mapper.Sc.Web.RequestContext.GetRootItem outerType : System.Web.HttpUnhandledException details :[{"parsedStack":[{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.ShowErrorMessage","level":0,"line":0},{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.Process","level":1,"line":0},{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"n/a","level":2,"line":0},{"assembly":"Sitecore.Kernel, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Pipelines.CorePipeline.Run","level":3,"line":0},{"assembly":"Sitecore.Kernel, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Pipelines.DefaultCorePipelineManager.Run","level":4,"line":0},{"assembly":"Sitecore.Kernel, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Pipelines.DefaultCorePipelineManager.Run","level":5,"line":0},{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Mvc.Pipelines.PipelineService.RunPipeline","level":6,"line":0},{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Mvc.Filters.PipelineBasedRequestFilter.OnException","level":7,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters","level":8,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass3_1.<BeginInvokeAction>b__5","level":9,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction","level":10,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Controller+<>c.<BeginExecuteCore>b__152_1","level":11,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid1.CallEndDelegate","level":12,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Controller.EndExecuteCore","level":13,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid1.CallEndDelegate","level":14,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Controller.EndExecute","level":15,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.MvcHandler+<>c.<BeginProcessRequest>b__20_1","level":16,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Async.AsyncResultWrapper+WrappedAsyncVoid`1.CallEndDelegate","level":17,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.MvcHandler.EndProcessRequest","level":18,"line":0},{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Mvc.Routing.RouteHttpHandler.EndProcessRequest","level":19,"line":0},{"assembly":"System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","method":"System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute","level":20,"line":0},{"assembly":"System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","method":"System.Web.HttpApplication.ExecuteStepImpl","level":21,"line":0},{"assembly":"System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","method":"System.Web.HttpApplication.ExecuteStep","level":22,"line":0}],"severityLevel":"Critical","outerId":"0","message":"An unhandled exception occurred.","type":"System.Web.HttpUnhandledException","id":"37238760"},{"parsedStack":[{"assembly":"Glass.Mapper.Sc, Version=5.5.28.0, Culture=neutral, PublicKeyToken=null","method":"Glass.Mapper.Sc.Web.RequestContext.GetRootItem","level":0,"line":0},{"assembly":"Aceto.Foundation.ErrorHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Aceto.Foundation.ErrorHandlers.Pipelines.MvcException.ExceptionWrappedExecuteRenderer.GetRenderingErrorModel","level":1,"line":0},{"assembly":"Aceto.Foundation.ErrorHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Aceto.Foundation.ErrorHandlers.Pipelines.MvcException.ExceptionWrappedExecuteRenderer.RenderError","level":2,"line":0},{"assembly":"Aceto.Foundation.ErrorHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Aceto.Foundation.ErrorHandlers.Pipelines.MvcException.ExceptionWrappedExecuteRenderer.Process","level":3,"line":0},{"assembly":"Aceto.Foundation.ErrorHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null","method":"n/a","level":4,"line":0},{"assembly":"Sitecore.Kernel, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Pipelines.CorePipeline.Run","level":5,"line":0},{"assembly":"Sitecore.Kernel, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Pipelines.DefaultCorePipelineManager.Run","level":6,"line":0},{"assembly":"Sitecore.Kernel, Version=13.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Pipelines.DefaultCorePipelineManager.Run","level":7,"line":0},{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Mvc.Pipelines.PipelineService.RunPipeline","level":8,"line":0},{"assembly":"Sitecore.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Sitecore.Mvc.Presentation.RenderingView.Render","level":9,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.ViewResultBase.ExecuteResult","level":10,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive","level":11,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive","level":12,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive","level":13,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters","level":14,"line":0},{"assembly":"System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35","method":"System.Web.Mvc.Async.AsyncControllerActionInvoker+<>c__DisplayClass3_1.<BeginInvokeAction>b__5","level":15,"line":0}],"severityLevel":"Critical","outerId":"37238760","message":"Object reference not set to an instance of an object.","type":"System.NullReferenceException","id":"1686768"}]

VigneshJothikumar avatar Jun 22 '20 06:06 VigneshJothikumar

Hi, can you format this any better? it is very hard to read the stack trace. Also the first place to start would be by checking the lifestyle of your DI container registrations for the Glass services.

mikeedwards83 avatar Jun 22 '20 08:06 mikeedwards83

Hi Mike,

This is how we are registered in the DI container, please have look and let me know you want more information.

public void Configure(IServiceCollection serviceCollection) { serviceCollection.AddTransient<ISitecoreService>(provider => new SitecoreService(Sitecore.Context.Database)); serviceCollection.AddScoped<IRequestContext, RequestContext>(); serviceCollection.AddScoped<IMvcContext, MvcContext>(); serviceCollection.AddScoped<IGlassHtml, GlassHtml>(); }

Thanks, Vignesh Jothikumar

VigneshJothikumar avatar Jun 22 '20 11:06 VigneshJothikumar

Hi Mike

After a couple of research, I just predicated this issue source "System.NullReferenceException at Glass.Mapper.Sc.Web.RequestContext.GetRootItem" might "System.Web.HttpUnhandledException" because I see the HTTP unhandled exception but I couldn't any solution for this. Can you please help me with this.

Thanks and Regards, Vignesh Jothikumar

VigneshJothikumar avatar Jun 30 '20 06:06 VigneshJothikumar

If you need immediate help then I can offer consultancy. Email me at [email protected] and I can give you rates and terms.

mikeedwards83 avatar Jun 30 '20 11:06 mikeedwards83