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.
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.
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
var umbHelper = new UmbracoHelper(UmbracoContext.Current);
var testNode = umbHelper.TypedContent(1);
if (testNode.HasValue("PropertyName", true))
{
var itemGroupName = testNode.GetPropertyValue<string>("PropertyName", true);
}
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:
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
Hi Mike,
Can you test like that :
Problem with typedContent or inside GetPropertyValue method.
Thanks, Alex
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
Really strange, but maybe checking will help
is working on a reply...