Sitecore Glass Mapper Null reference exception on some model properties

1.8k views Asked by At

I have upgrade to GlassMapper version 4.0.1.8 and I'm experiencing strange behavior with some model properties.

All my models are generated by TDS and most of them work fine. On one model Glass Mapper threw a null-reference exception on one specific property and all properties in the base-models. After settings lazy-loading to false for all properties of the model, the issue disappeared...

However, after that I set the SitecoreFieldSettings.DontLoadLazily on all my model properties, since they all are generated by TDS, but now another property of a different model is giving me the same exception and this property is also not lazyloaded.

This is the exception:

Exception: System.NullReferenceException 
Message: Object reference not set to an instance of an object. 
Source: Glass.Mapper 
at Glass.Mapper.AbstractService.InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext) 
at Glass.Mapper.Pipelines.ObjectConstruction.Tasks.CreateConcrete.LazyObjectInterceptor.Intercept(IInvocation invocation) 
at Castle.DynamicProxy.AbstractInvocation.Proceed() 
at Castle.Proxies.ListitemLinkProxy.get_Link() 
at ASP._Page_Views_MyProject_Pages_MyPage_cshtml.Execute() in c:\mycode.cshtml:line 86 
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() 
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() 
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) 
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) 
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 

1) Why does Glass mapper throws this exception on some fields if they are lazyloaded?

2) Why am I getting the same exception on a different field which is not lazy loaded after lazy-loading the fields of the first model?

0

There are 0 answers