Glass.Mapper
Glass.Mapper copied to clipboard
Using SitecoreService in computed index field - getting NRE when checking to see if cache enabled.
@mikeedwards83, Thanks for helping me understand the other issue. Since upgrading to the latest version of Glass, our computed index fields are now returning NREs.
Code is as follows:
var item = (Item)scIndexable;
if (item == null)
{
return null;
}
if (item.TemplateID != ID.Parse(Guid.Parse(SitecoreTemplatesId.Research.MakeTemplate)))
{
return null;
}
var context = new Glass.Mapper.Sc.SitecoreService(item.Database);
var make = context.GetItem<CarMake>(item.ID.Guid);
var result = make.UrlFragment.ToLower();
return result;
The stack trace is consistent with all the computed fields.
StackTrace " at Glass.Mapper.Sc.SitecoreTypeCreationContext.get_CacheEnabled() in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreTypeCreationContext.cs:line 74
at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CacheCheck.CacheCheckTask.Execute(ObjectConstructionArgs args)
in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\ObjectConstruction\Tasks\CacheCheck\CacheCheckTask.cs:line 16
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args)
in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 77
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args)
in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 80
at Glass.Mapper.Pipelines.AbstractPipelineRunner`2.<>c__DisplayClass3.<CreateTaskExpression>b__2(T args)
in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\Pipelines\AbstractPipelineRunner.cs:line 80
at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext)
in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper\AbstractService.cs:line 138
at Glass.Mapper.Sc.SitecoreService.CreateType(Type type, Item item, Boolean isLazy, Boolean inferType, Dictionary`2 parameters, Object[] constructorParameters)
in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreService.cs:line 495
at Glass.Mapper.Sc.SitecoreService.GetItem[T](Guid id, Boolean isLazy, Boolean inferType)
in c:\TeamCity\buildAgent\work\8567e2ba106d3992\Source\Glass.Mapper.Sc\SitecoreService.cs:line 898
Are you using a Cachable model?
@mikeedwards83 - yes I am using a cachable model. It's a complex type with 2 properties that bring in other models also cachable. I've decorated those two properties with DontLoadLazily setting. I have since moved my computed index field classes back to sitecore Item API as a temporary workaround.