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
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.
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.
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) :-(
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.
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.
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.
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:
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:
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...
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.
TypedContent(1234) returns NullReferenceException
Hi
We are using the grid with DocTypeGridEditors.
In my view there is this code snippet:
this line returns a null
NullReferenceException
in the backend in the frontend it works flawless.any idea why this happens?
stacktrace:
Hi Tobias,
What do you mean backend? Are you using webApiUmbraco controller or surfaceController?
Maybe Umbraco helper is null?
Thanks
The grid editors preview in the umbraco. Nope i'm not using one of these. Already thought of that.
I'm getting this intermittently on the front-end (v.7.4.3). Publishing the entire site appears to get rid of it.
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...
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 orpreviewSet
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).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
It "worked" :P
What I did:
umb_preview
cookieumb_preview
cookie presentumb_preview
cookie is also present.So it doesn't create the preview correctly, am i right?
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
I've debugged it a bit more.
What I found out is, that is loses the
UmbracoContext.Current.CurrentUser
at https://github.com/leekelleher/umbraco-doc-type-grid-editor/blob/develop/src/Our.Umbraco.DocTypeGridEditor/Web/Extensions/HtmlHelperExtensions.cs#L127So it has no User at this point: https://github.com/umbraco/Umbraco-CMS/blob/99a7aa53a1e53f4e0f186e7fb268d287da0cbbf3/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs#L393
Maybe Umbraco changed something with the previewing thingy... Have you tested the dtge with the latest umbraco?
EDIT
Already lost the umbracouser here: https://github.com/leekelleher/umbraco-doc-type-grid-editor/blob/develop/src/Our.Umbraco.DocTypeGridEditor/Web/Attributes/DocTypeGridEditorPreviewAttribute.cs#L13
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
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.
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:
Republishing the site doesn't seem to help.
Note that the FaqQuestion content type does not have a grid editor on it.
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:
On this site we use a custom URL provider, which made a call to GetById on the content cache:
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:
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:
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...
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.
is working on a reply...