Copied to clipboard

Flag this post as spam?

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


  • Mike Taylor 155 posts 353 karma points
    Jan 22, 2016 @ 12:37
    Mike Taylor
    0

    Recursive GetPropertyValue throwing NullReferenceException on LIVE server only

    I have an event wired into ContentService.Published, which contains (among other things) a simple call to a recursive GetPropertyValue:

    var umbHelper = new UmbracoHelper(UmbracoContext.Current);
    var itemGroupName = umbHelper.TypedContent(item.Id).GetPropertyValue<string>("PropertyName", true);
    

    On the LIVE server, when I publish one of TWO particular nodes, I'm getting a NullReferenceException, which is barfing at this call to GetPropertyValue, giving me a "Object reference not set to an instance of an object" error.

    Peculiar, so I took a DB backup, and restored to my local dev machine - rebuilt indexes etc., and tried to publish the same nodes - and they published FINE. Same code, same database.

    Have tried rebuilding indexes on live site, restarting DB, restarting IIS, restarting server - am flummoxed as to why these two nodes are problematic on LIVE but not on DEV.

    Anyone got any ideas?

    Thanks,

    Mike

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jan 22, 2016 @ 13:45
    Alex Skrypnyk
    0

    Hi Mike,

    Can you test like that :

                var umbHelper = new UmbracoHelper(UmbracoContext.Current);
                var node = umbHelper.TypedContent(item.Id);
                if (node != null)
                {
                    var itemGroupName = node.GetPropertyValue<string>("PropertyName", true);
    
                }
    

    Problem with typedContent or inside GetPropertyValue method.

    Thanks, Alex

  • Mike Taylor 155 posts 353 karma points
    Jan 22, 2016 @ 13:50
    Mike Taylor
    0

    Hi Alex,

    I'll give that a try - the stack trace suggests it's the GetPropertyValue method, but if it was a problem with either, surely it would break on DEV as well as on LIVE?

    Message: [NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias, Boolean recurse, Boolean withDefaultValue, T defaultValue):0 Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias, Boolean recurse):0 Flag.GeeTee.Events.Publishing.ProductPublish.ContentService_Published(IPublishingStrategy sender, PublishEventArgs`1 e):351 Umbraco.Core.Events.TypedEventHandler`2.Invoke(TSender sender, TEventArgs e):-1 Umbraco.Core.Services.ContentService.SaveAndPublishDo(IContent content, Int32 userId, Boolean raiseEvents):361 umbraco.cms.businesslogic.web.Document.SaveAndPublishWithResult(User u):159 umbraco.cms.presentation.editContent.Publish(Object sender, EventArgs e):18 System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e):25 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument):38 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint):1515

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jan 22, 2016 @ 14:12
    Alex Skrypnyk
    0

    Really strange, but maybe checking will help

                var umbHelper = new UmbracoHelper(UmbracoContext.Current);
                var testNode = umbHelper.TypedContent(1);
                if (testNode.HasValue("PropertyName", true))
                {
                    var itemGroupName = testNode.GetPropertyValue<string>("PropertyName", true);
                }
    
Please Sign in or register to post replies

Write your reply to:

Draft