Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anders Ekelund 3 posts 73 karma points
    Dec 09, 2015 @ 20:57
    Anders Ekelund
    0

    TypedContent giving Nullreference

    Hi!

    We have a problem that occurs occasionally. We get NullreferenceException when we try to get a TypedContent from a UmbracoHelper. I cannot figure out why this is occuring but restarting or deleting index files fixes the problem.

    The error is: Object reference not set to an instance of an object. at Umbraco.Web.UmbracoContext.getUmbracoUser() at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.<getGetXmlDelegate>b3(UmbracoContext context, Boolean preview) at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.GetXml(UmbracoContext umbracoContext, Boolean preview) at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.GetById(UmbracoContext umbracoContext, Boolean preview, Int32 nodeId) at Umbraco.Web.PublishedCache.ContextualPublishedCache1.GetById(Boolean preview, Int32 contentId) at Umbraco.Web.UmbracoHelper.TypedContent(String id) at Energiforsk.Extensions.DocumentTypeExtensions.GetImageCarouselItems(StartPageViewModel source) at ASP._Page_Views_Partials__CarouselMobile_cshtml.Execute() in d:\home\site\wwwroot\Views\Partials\_CarouselMobile.cshtml:line 19 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.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection) at System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName, Object model) at ASP._Page_Views_Master_cshtml.Execute() in d:\home\site\wwwroot\Views\Master.cshtml:line 73 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.WebPages.WebPageBase.&lt;&gt;c__DisplayClass3.&lt;RenderPageCore&gt;b__2(TextWriter writer) at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) at System.Web.WebPages.WebPageBase.Write(HelperResult result) at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action1 body) at System.Web.WebPages.WebPageBase.PopContext() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass21.<>cDisplayClass2b.<BeginInvokeAction>b1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass21.<BeginInvokeAction>b1e(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<BeginExecuteCore>b1d(IAsyncResult asyncResult, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<BeginExecute>b15(IAsyncResult asyncResult, Controller controller) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    The class where the Exception occurs is a static HtmlHelper extension class:

    private static UmbracoHelper Umbraco { get { return new UmbracoHelper(UmbracoContext.Current); } }

        public static IEnumerable<ImageCarouselItemViewModel> GetImageCarouselItems(this StartPageViewModel source)
        {
            if (source == null)
                return Enumerable.Empty<ImageCarouselItemViewModel>();
    
            if (string.IsNullOrEmpty(source.LinkToImageCarousel))
                return Enumerable.Empty<ImageCarouselItemViewModel>();
    
            var list = new List<ImageCarouselItemViewModel>();
    
            if (source.LinkToImageCarousel == null)
                return Enumerable.Empty<ImageCarouselItemViewModel>();
    
            var page = Umbraco.TypedContent(source.LinkToImageCarousel);
    
            if (page == null)
                return Enumerable.Empty<ImageCarouselItemViewModel>();
    
            foreach (var node in page.Descendants())
            {
                var imageCarouselItem = Umbraco.TypedContent(node.Id).As<ImageCarouselItemViewModel>();
    
                list.Add(imageCarouselItem);
            }
            return list;
        }
    

    Does anyone know why this problem is occuring?

  • Matthieu Nelmes 102 posts 385 karma points
    Dec 09, 2015 @ 23:56
    Matthieu Nelmes
    0

    Can't see why it would randomly return a null.

    Is this a development environment or live?

    I've only had issues like this where I have a local and staging environment sharing the same DB connection. So there would be instances where the DB would be up-to-date but my local XML cache would be out of date.

    Try republishing the site, as I think I'm correct in thinking TypedContent returns IPublishedContent

  • Anders Ekelund 3 posts 73 karma points
    Feb 06, 2016 @ 13:13
    Anders Ekelund
    0

    Sorry for a late response.

    The error does not appear anymore and I wrote a helper class for getting a new instance.

    We had a shared db connection before and that is changed now in production.

    But now we get a lock on the index instead like "Cannot index queue items, the index is currently locked,, IndexSet: InternalIndexSet"

    Any idea of this error?

  • Daniel 60 posts 174 karma points
    Feb 06, 2016 @ 17:44
    Daniel
    0

    Try manually physically deleting your indexes and rebuild them again in the Developer tab in Umbraco, path is at: /App_Data/TEMP/ExamineIndexes/ * - just delete everything in there, everything is rebuilt!

    You may get some sort of permission error to not be able to delete it, I think the last I shut down the IIS and had to do a "del ExamineIndexes" or similar via the command prompt.

Please Sign in or register to post replies

Write your reply to:

Draft