Copied to clipboard

Flag this post as spam?

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


  • Matthew Berner 47 posts 327 karma points
    Apr 16, 2020 @ 17:27
    Matthew Berner
    0

    Null exception for sidebars in Local environment

    I am getting these errors only my local testing, our live site is not getting the errors. I am not sure what is happening: Here is the error message, I am stuck:

     Line 20: 
    Line 21: <aside class="sidebar float-left">
    Line 22:     @Umbraco.RenderMacro("sidebarWidget")
    Line 23:                 </aside>
    Line 24:             </section>
    
    Source File: c:\users\fwfa.desktop-bdtcijl\documents\visual studio 2015\Projects\KFA_Recipe_Test\KFA_Recipe_Test\Views\Partials\leftsidebar.cshtml    Line: 22
    
    Stack Trace:
    
    
    [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Core.Persistence.Database.BeginTransaction(IsolationLevel isolationLevel) +121
       Umbraco.Core.Scoping.Scope.get_Database() +579
       Umbraco.Core.Persistence.Repositories.<PerformGetByQuery>d__9.MoveNext() +401
       System.Linq.WhereEnumerableIterator`1.MoveNext() +246
       System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +209
       Umbraco.Core.Services.MacroService.GetByAlias(String alias) +507
       umbraco.cms.businesslogic.macro.<>c__DisplayClass55_0.<GetByAlias>b__0() +69
       Umbraco.Core.Cache.<>c__DisplayClass0_0`1.<GetCacheItem>b__0() +18
       Umbraco.Core.Cache.<>c__DisplayClass10_0.<GetSafeLazy>b__0() +30
    
    [Exception: Exception while creating a value.]
       Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, CacheDependency dependency) +955
       Umbraco.Core.Cache.HttpRuntimeCacheProvider.GetCacheItem(String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) +146
       Umbraco.Core.Cache.DeepCloneRuntimeCacheProvider.GetCacheItem(String cacheKey, Func`1 getCacheItem, Nullable`1 timeout, Boolean isSliding, CacheItemPriority priority, CacheItemRemovedCallback removedCallback, String[] dependentFiles) +176
       umbraco.cms.businesslogic.macro.Macro.GetByAlias(String alias) +355
       umbraco.macro..ctor(String alias) +172
       Umbraco.Web.UmbracoComponentRenderer.RenderMacro(String alias, IDictionary`2 parameters, page umbracoPage) +61
       ASP._Page_Views_Partials_leftsidebar_cshtml.Execute() in c:\users\fwfa.desktop-bdtcijl\documents\visual studio 2015\Projects\KFA_Recipe_Test\KFA_Recipe_Test\Views\Partials\leftsidebar.cshtml:22
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +148
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +122
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +200
       System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper htmlHelper, String partialViewName) +99
       ASP._Page_Views_textPage_cshtml.Execute() in c:\users\fwfa.desktop-bdtcijl\documents\visual studio 2015\Projects\KFA_Recipe_Test\KFA_Recipe_Test\Views\textPage.cshtml:20
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +148
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +200
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +91
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
       System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +188
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +32
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +39
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +46
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +651
       System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +220
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4075.0
    

    Here is the code where the issue lies: It is a Macro that produces a sidebar widget (widget_items) is correct.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        //get all children of type 'widget_item'
        var kfawidgets = @CurrentPage.Children.Where("DocumentTypeAlias == \"widget_items\"");
    }
    <div class="widgetzone">
        @foreach (var kfawidget in @kfawidgets)
        {
            <div class="widget @kfawidget.className">
    
                @if ((@kfawidget.widgetHeader != "socialstrata") && (@kfawidget.widgetHeader != "store"))
                {
                    <h4 class="widget-header">
                        @kfawidget.widgetHeader
                        <span class="pull-right"></span>
                    </h4>
    
                }
                <div class="widget-content" style="margin-top:15px">
                    @kfawidget.widgetContent
                </div>
    
    
            </div>
        }
    </div>
    

    This macro is:

        @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Recipes.Models.pocos
    @using Recipes.Models
    
    <ul style="list-style-type:none">
          <li><a href="/recipes-diet/?cat=0#res">All Categories</a></li>
        @foreach (var CategoryName in RecipFunctions.GetAllCategories())
        {
                <li><a href="/[email protected]#res">@CategoryName.CategoryName</a></li>
    
        }
        </ul>
    

    Thanks Matthew Berner

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 16, 2020 @ 17:41
    Alex Skrypnyk
    0

    Hi Matthew

    Check the foreach to null, maybe there is some null

  • Matthew Berner 47 posts 327 karma points
    Apr 16, 2020 @ 18:14
    Matthew Berner
    100

    Alex: I found the bug. I was using the class for the Macro itself Thanks for your help Matthew Berner

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies