Copied to clipboard

Flag this post as spam?

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


  • Tobias Lopez 64 posts 210 karma points
    Apr 19, 2016 @ 14:32
    Tobias Lopez
    1

    TypedContent(1234) returns NullReferenceException

    Hi

    We are using the grid with DocTypeGridEditors.

    In my view there is this code snippet:

    var node = Umbraco.TypedContent(nodeId);
    

    this line returns a null NullReferenceExceptionin the backend in the frontend it works flawless.

    any idea why this happens?

    stacktrace:

    at umbraco.presentation.preview.PreviewContent.EnsureInitialized(User user, String previewSet, Boolean validate, Action initialize)
    at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.<get_GetXmlDelegate>
    b__3(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.ContextualPublishedCache`1.GetById(Boolean preview, Int32 contentId)
    at Umbraco.Web.PublishedCache.ContextualPublishedCache.GetById(Int32 contentId)
    at Umbraco.Web.PublishedContentQuery.TypedDocumentById(Int32 id, ContextualPublishedCache cache)
    at Umbraco.Web.PublishedContentQuery.<>c__DisplayClass1.<TypedDocumentsByIds>
        b__0(Int32 eachId)
        at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
        at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
        at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
        at ASP._P
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Apr 20, 2016 @ 08:59
    Alex Skrypnyk
    0

    Hi Tobias,

    What do you mean backend? Are you using webApiUmbraco controller or surfaceController?

    Maybe Umbraco helper is null?

    Thanks

  • Tobias Lopez 64 posts 210 karma points
    Apr 21, 2016 @ 06:26
    Tobias Lopez
    0

    The grid editors preview in the umbraco. Nope i'm not using one of these. Already thought of that.

  • David Peck 687 posts 1863 karma points c-trib
    Jun 28, 2016 @ 13:50
    David Peck
    0

    I'm getting this intermittently on the front-end (v.7.4.3). Publishing the entire site appears to get rid of it.

    [NullReferenceException: Object reference not set to an instance of an object.]
    
       umbraco.presentation.preview.PreviewContent.EnsureInitialized(User user, String previewSet, Boolean validate, Action initialize) +88
       Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.<get_GetXmlDelegate>b__3(UmbracoContext context, Boolean preview) +132
       Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.GetXml(UmbracoContext umbracoContext, Boolean preview) +28
       Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.GetById(UmbracoContext umbracoContext, Boolean preview, Int32 nodeId) +20
       Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.DetermineRouteById(UmbracoContext umbracoContext, Boolean preview, Int32 contentId) +35
       Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.GetRouteById(UmbracoContext umbracoContext, Boolean preview, Int32 contentId) +86
       Umbraco.Web.Routing.DefaultUrlProvider.GetUrl(UmbracoContext umbracoContext, Int32 id, Uri current, UrlProviderMode mode) +96
       Umbraco.Web.Routing.<>c__DisplayClass3.<GetUrl>b__0(IUrlProvider provider) +28
       System.Linq.WhereSelectArrayIterator`2.MoveNext() +66
       System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +94
       Umbraco.Web.Routing.UrlProvider.GetUrl(Int32 id, Uri current, UrlProviderMode mode) +169
       Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(String text) +285
       Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(String text, Boolean preview) +80
       Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview) +71
       Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0() +39
       System.Lazy`1.CreateValue() +415
       System.Lazy`1.LazyInitValue() +152
       System.Lazy`1.get_Value() +75
       Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__1() +20
       System.Lazy`1.CreateValue() +415
       System.Lazy`1.LazyInitValue() +152
       System.Lazy`1.get_Value() +75
       Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value() +9
       Umbraco.Web.PublishedPropertyExtension.GetValue(IPublishedProperty property, Boolean withDefaultValue, T defaultValue) +73
       Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias, Boolean recurse, Boolean withDefaultValue, T defaultValue) +82
       Umbraco.Web.PublishedContentExtensions.GetPropertyValue(IPublishedContent content, String alias) +59
    
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 15, 2016 @ 13:26
    Lee Kelleher
    0

    The null reference exception is coming from umbraco.presentation.preview.PreviewContent.EnsureInitialized - so it's a case of figuring out what is null and why.

    The latest source code for that method is...

    public void EnsureInitialized(User user, string previewSet, bool validate, Action initialize)
    {
        lock (_initLock)
        {
            if (_initialized) return;
    
            _userId = user.Id;
            ValidPreviewSet = UpdatePreviewPaths(new Guid(previewSet), validate);
            initialize();
            _initialized = true;
        }
    }
    

    For ref: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/umbraco.presentation/umbraco/preview/PreviewContent.cs#L48

    Breaking it down, the null reference is either coming from the user object or previewSet value.

    The user object shouldn't be null, since you are already logged into the back-office, (unless there's something else corrupted and that'd be worrying).

    If you want to check this, in your view/partial add this: @(UmbracoContext.Current.Security.CurrentUser) - if that throws a null reference, that's the issue

    The previewSet value might be wrong or invalid. Check your browser to see if you have a cookie called "UMB_PREVIEW" and that the value looks like a GUID. If it's not there or doesn't look like a GUID, then that's the issue - clear your cookies and try again.

    I hope this helps?

    Cheers, - Lee

  • Tobias Lopez 64 posts 210 karma points
    Sep 15, 2016 @ 13:40
    Tobias Lopez
    0

    It "worked" :P

    What I did:

    1. Open the node with the grid editor - got the error from above
    2. Checked the cookies - no umb_preview cookie
    3. Opened the actual preview mode - umb_preview cookie present
    4. Went back to the grid editor - now it renders the previews correctly without error and the umb_preview cookie is also present.

    So it doesn't create the preview correctly, am i right?

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 15, 2016 @ 13:57
    Lee Kelleher
    0

    Just to clarify, this isn't DTGE itself causing the error, it appears to be Preview Mode is (somehow) kicking in when DTGE is trying to render the view/markup for the cell... but the "UMB_PREVIEW" cookie is missing.

    The question is why does Umbraco think it's in Preview Mode when it doesn't have the cookie? Hmmm... (I wish I knew the answer) :-(

    Cheers,
    - Lee

  • Tobias Lopez 64 posts 210 karma points
    Sep 16, 2016 @ 09:22
  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 16, 2016 @ 10:04
    Lee Kelleher
    0

    Thanks Tobias, good debugging work!

    I'm using DTGE on 7.4.3 (haven't tried on 7.5x yet).

    I'll take a look at the lines of code you've flagged up - it does seem strange that the CurrentUser gets lost in DTGE code. I'll let you know what I find.

    Thanks,
    - Lee

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Sep 26, 2016 @ 19:57
    Lee Kelleher
    0

    Hi Tobias,

    I've tried to reproduce the scenario/errors that you've been getting, but unfortunately I haven't been able to, it all works fine for me. (Sorry to say)

    I'm not sure what else I can do to help resolve this for you :-(

    If it can be identified as a bug within DTGE, I'm totally happy to take on a fix, but I can't find where the underlying issue is, sorry.

  • Geoff Beaumont 75 posts 104 karma points
    Oct 10, 2016 @ 12:23
    Geoff Beaumont
    0

    Hi Lee,

    I don't think it's DTGE - I'm seeing this error (on Umbraco 7.4.3), and it seems to be related to a standard Rich Text field (specifically, to Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks). This is hitting the XmlPublishedCache and then dropping into umbraco.presentation.preview.PreviewContent.EnsureInitialized - it's doing it regardless of whether the request contains any Umbraco back office cookies (I get the same when accessing the site with a browser which is logged into the back office and one that isn't - in fact, I picked the issue up when running a spider across the site).

    This is the stack trace I have:

    2016-10-10 12:06:39,821 [P13028/D4/T79] ERROR Umbraco.Core.UmbracoApplicationBase - An unhandled exception occurred
    
    System.NullReferenceException: Object reference not set to an instance of an object.
    
    at umbraco.presentation.preview.PreviewContent.EnsureInitialized(User user, String previewSet, Boolean validate, Action initialize)
    
    at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.<get_GetXmlDelegate>b__3(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.ContextualPublishedCache`1.GetById(Boolean preview, Int32 contentId)
    
    at Umbraco.Extensions.UrlProvider.CustomCachedUrlProvider.GetUrl(UmbracoContext umbracoContext, Int32 id, Uri current, UrlProviderMode mode)
    
    at Umbraco.Web.Routing.UrlProvider.<>c__DisplayClass3.<GetUrl>b__0(IUrlProvider provider)
    
    at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
    
    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
    
    at Umbraco.Web.Routing.UrlProvider.GetUrl(Int32 id, Uri current, UrlProviderMode mode)
    
    at Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(String text)
    
    at Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(String text, Boolean preview)
    
    at Umbraco.Web.PropertyEditors.ValueConverters.RteMacroRenderingValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview)
    
    at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0()
    
    at System.Lazy`1.CreateValue()
    
    at System.Lazy`1.LazyInitValue()
    
    at System.Lazy`1.get_Value()
    
    at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__1()
    
    at System.Lazy`1.CreateValue()
    
    at System.Lazy`1.LazyInitValue()
    
    at System.Lazy`1.get_Value()
    
    at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value()
    
    at Umbraco.Web.PublishedPropertyExtension.GetValue[T](IPublishedProperty property, Boolean withDefaultValue, T defaultValue)
    
    at Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias, Boolean recurse, Boolean withDefaultValue, T defaultValue)
    
    at Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias)
    
    at Umbraco.Web.PublishedContentModels.FaqQuestion.get_Answer()
    
    at Umbraco.Extensions.Controllers.HelpAdviceController.<>c.<SearchFaqsList>b__1_0(FaqQuestion faq)
    

    Republishing the site doesn't seem to help.

    Note that the FaqQuestion content type does not have a grid editor on it.

  • Geoff Beaumont 75 posts 104 karma points
    Dec 13, 2016 @ 11:07
    Geoff Beaumont
    1

    Okay, this issue has reared it's ugly head again for us - but I think I've got somewhere with it (at least in our specific setup).

    The key was these lines from the stack trace:

    at Umbraco.Web.PublishedCache.ContextualPublishedCache`1.GetById(Boolean preview, Int32 contentId)
    at Umbraco.Extensions.UrlProvider.CustomCachedUrlProvider.GetUrl(UmbracoContext umbracoContext, Int32 id, Uri current, UrlProviderMode mode)
    

    On this site we use a custom URL provider, which made a call to GetById on the content cache:

    content = umbracoContext.ContentCache.GetById(id);
    

    Note that it was using the method which takes only a content ID and not the boolean preview switch - however, the stack trace shows execution passing directly to the version of the method with takes both parameters - so presumably the compiler has optimised this step away?

    Digging in the Umbraco source code I found that the ID only method is defined on Umbraco.Web.PublishedCache.ContextualPublishedCache (which the actual instance UmbracoContext.ContentCache inherits from via several levels - it's in fact a ContextualPublishedContentCache). This method sets the preview mode from the UmbracoContext:

    public IPublishedContent GetById(int contentId)
    {
        return GetById(UmbracoContext.InPreviewMode, contentId);
    }
    

    But what will preview be set to if the compiler has bypassed this method? Good question! Clearly it can sometimes be true even when it definitely shouldn't be.

    So, the fix in our case has been to explicitly set preview to false:

    content = umbracoContext.ContentCache.GetById(false, id);
    

    I'm still testing this, so I'm not sure if it'll have any nasty side effects. Arguably I should be passing UmbracoContext.InPreviewMode rather than false, so I may have issues when it really is previewing.

    It's also worth noting that the intermittent nature of the issue on this site may simply have been down to caching - the custom URL provider checks for cached results before it reaches the GetById call, so if the URL for the content ID has already been successfully looked up that'll be returned without a problem.

    There is still the rather obvious unsolved question; why do we only have this issue when the URL provider is called in the context of resolving URLs in RTE content? I've added debug output and confirmed this is definitely the case (when we hit this issue we're always resolving the URL of a content ID in RTE markup - yet the same ID is resolved without a problem elsewhere). But I've no idea why the code would behave differently - unless the stack trace is not actually correct and the ID only GetById method is called, and for some reason when parsing the RTE content UmbracoContext.InPreviewMode is true...which would be truly horrible...

  • Geoff Beaumont 75 posts 104 karma points
    Dec 13, 2016 @ 15:14
    Geoff Beaumont
    0

    Worth adding to this that after further testing, setting the preview parameter to UmbracoContext.InPreviewMode doesn't fix the problem - only hard coding it to false.

    So, it appears that somewhere within the RTE content parsing the preview mode is switched on - though quite why mystifies me.

    I would appear that the stack trace bypassing the ID only method was a red herring.

Please Sign in or register to post replies

Write your reply to:

Draft