Glass.Mapper
Glass.Mapper copied to clipboard
NullReferenceException after some recycles on version 4.3.4.197
There's nothing particularly interesting about where it's happening, but it happens on a SitecoreContext GetItem call. Happens only after recycling if there is activity on the site immediately. After subsequent recycles can sometimes work just fine. Once it's broke though, it won't fix itself without a recycle. Won't happen locally but I haven't yet tried making a script to keep hitting the site.
Very similar to what was seen in https://github.com/mikeedwards83/Glass.Mapper/issues/137 -- except it sounds like the issue was fixed in that earlier version.
Also I verified there was nothing weird like multiple classes mapping to the same GUIDs. Any thoughts?
Exception below:
[NullReferenceException: Object reference not set to an instance of an object.]
Glass.Mapper.Sc.SitecoreService.GetItem(Guid id, Boolean isLazy, Boolean inferType) in c:\Source\Glass.Mapper.Sc\SitecoreService.cs:906
Some.Namespace.Here.<>c__DisplayClass23_0.<.ctor>b__1() in D:\source\SomeFile.cs:66
System.Lazy`1.CreateValue() +689
System.Lazy`1.LazyInitValue() +442
Some.Namespace.Here.<>c__DisplayClass23_1.<.ctor>b__2() in D:\source\SomeFile.cs:66:73
System.Lazy`1.CreateValue() +689
System.Lazy`1.LazyInitValue() +442
Glass should boot in the during the Sitecore initialization pipeline
Can you add logging to see that this happens before the error is thrown?
I know this is old but I am seeing the same thing happen with 5.1.13. I have not yet been able to get additional logging about this but it appears to be resolved with an app pool reset.
[NullReferenceException: Object reference not set to an instance of an object.]
Glass.Mapper.Sc.GetItemByQueryOptions.GetItem(Database database) in
C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\OptionsGetItem.cs:125
Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in
C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:334
Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in
C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:318`
Can you post the query you are exciting or the piece of coding that is calling this?
On Wed, 5 Dec 2018, 15:38 Todd, [email protected] wrote:
I know this is old but I am seeing the same thing happen with 5.1.13. I have not yet been able to get additional logging about this but it appears to be resolved with an app pool reset.
[NullReferenceException: Object reference not set to an instance of an object.] Glass.Mapper.Sc.GetItemByQueryOptions.GetItem(Database database) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\OptionsGetItem.cs:125 Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:334 Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:318`
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mikeedwards83/Glass.Mapper/issues/340#issuecomment-444529419, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHj0MLkPSWuLM4DgSzMev4AFBZ5qSiiks5u1-h4gaJpZM4RSSyK .
Sorry for the delay on this @mikeedwards83
This is the query we are making.
var getItems = new GetItemByQueryBuilder()
.Query(
$"{rootpath}//*[contains(@@name,'{theSearchPhrase}')]");
var clientSetting = this.contentRepository.GetItem<IMyTemplate>(getItems.Options);
It seems to only happen when trying to load this CD website on a box that is also running CM. At least that is the only use case we have seen it happen in. An app pool reset and it starts working again.
Another follow up to this. I am seeing all this on Glass Mapper version 5.3.15 as well so may just want to push this to a different issue. However, it seems to happen only on the CM server and it seems to happen when a request to a CM page (content editor) is issued at the same time as a request to a CD page (any CD landing page). So seems like an initialization overlap and lockout when both are running together.
Am I correct in assuming that this request is made to the same server at the same time?
Yes, that is correct.
What are the lifestyles of the different services, e.g. RequestContext, MvcContext, SitecoreContext. Are they transient, scoped or static?
serviceCollection.AddTransient<ISitecoreService>(provider => new SitecoreService(Context.Database));
serviceCollection.AddScoped<IRequestContext, RequestContext>();
serviceCollection.AddScoped<IMvcContext, MvcContext>();
serviceCollection.AddScoped<IGlassHtml, GlassHtml>();
Trying to do some testing to see if changing this resolve the issue. Sadly the issue is hard to reproduce on purpose.
What is odd is that the error isn't cleared until there is an IIS reset. However each request should generate a new instance.
Do you have a full stack trace and an example of the calling code that throws the error?
[NullReferenceException: Object reference not set to an instance of an object.]
Glass.Mapper.Sc.GetItemByQueryOptions.GetItem(Database database) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\OptionsGetItem.cs:125
Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:334
Glass.Mapper.Sc.SitecoreService.GetItem(GetItemOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc\SitecoreService.cs:318
(Object , Object ) +53
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +483
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +235
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +21
Sitecore.Web.RequestEventsHandler.OnPostAuthenticateRequest(HttpContextBase context) +213
Sitecore.Nexus.Web.HttpModule.(Object , EventArgs ) +306
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +222
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +212
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +90
@mikeedwards83 I am getting the same above error when I call var datasource = GetDataSource<IServiceOptionsDatasource>();

at Glass.Mapper.Sc.Web.Mvc.MvcContext.GetDataSourceItem[T](GetKnownOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc.Mvc\Web\Mvc\IMvcContext.cs:line 106 at Glass.Mapper.Sc.Web.Mvc.GlassController.GetDataSource[T](GetKnownOptions options) in C:\TeamCity\buildAgent\work\9693a2d38f55a4a\Source\Glass.Mapper.Sc.Mvc\Web\Mvc\GlassController.cs:line 93