Ribbon control exception during page preview
Asked Answered
J

3

5

Hi when loading page during preview I have not loaded ribbon. Do you have any clues how to fix it?

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   Sitecore.Data.Database.ApplySecurity(Item[] items) +112
   Sitecore.Data.Database.SelectItems(String query) +252
   Sitecore.Shell.Applications.WebEdit.Commands.OpenMyItems.GetHeader(CommandContext context, String header) +188
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderSmallButton(HtmlTextWriter output, Item button, CommandContext commandContext) +307
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderButton(HtmlTextWriter output, Item button, CommandContext commandContext) +732
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunk(HtmlTextWriter output, Item chunk, CommandContext commandContext) +330
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunk(HtmlTextWriter output, Item chunk, CommandContext commandContext, Boolean isContextual, String id) +204
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunk(HtmlTextWriter output, Item chunk, CommandContext commandContext, Boolean isContextual) +242
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunks(HtmlTextWriter output, Item strip, CommandContext commandContext, Boolean isContextual) +442
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderStrips(HtmlTextWriter output, Item ribbon, Boolean isContextual, ListString visibleStripList) +800
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderStrips(HtmlTextWriter output, Item defaultRibbon, Item contextualRibbon, ListString visibleStripList) +215
   Sitecore.Web.UI.WebControls.Ribbons.Ribbon.Render(HtmlTextWriter output) +610
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +149
   Sitecore.Web.HtmlUtil.RenderControl(Control ctl) +74
   Sitecore.Shell.Applications.WebEdit.WebEditRibbonForm.RenderRibbon(Item item) +603
   Sitecore.Shell.Applications.WebEdit.WebEditRibbonForm.OnLoad(EventArgs e) +1238

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +76
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +193
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +35
   Sitecore.Web.UI.Sheer.ClientPage.OnLoad(EventArgs e) +337
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
Jaques answered 6/8, 2013 at 17:34 Comment(0)
S
8

From the stack trace information looks like the problem is with the My Items button in ribbon.

enter image description here

It seems that for some reason the fast query which is executed while loading this button returns a list of items which contain null. Do you have any custom data provider?

There are 2 solutions you can try:

  • clear cache on the /sitecore/admin/cache.aspx page
  • find the items which are causing the troubles by running this query as admin
Item[] items = Sitecore.Client.ContentDatabase.SelectItems(
    "fast://*[@__lock='%\"full-username-which-experienced-exception-with-domain-name\"%']");

The other option is to hide this button from ribbon (in core database remove or change security rights of /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Page Editor/Edit/My Items). From my experience this button is rarely used in the Page Editor mode and can slow down Page Editor as every time this mode is loaded, My items button counts all the articles which are locked by the current user so removing it might be a good idea anyway.

Soult answered 6/8, 2013 at 18:35 Comment(7)
Can you please explain how I can run this query as admin?Jaques
I use standard MS SQL connection at my local database. Thanks.Jaques
This code can be added to any of your pages - just for debugging option. Not as a permanent change. Remember to put the proper user name in this query. And login as admin to Sitecore. But if users don't use My Items button in Page Editor I do recommend you to remove /sitecore/content/Applications/WebEdit/Ribbons/WebEdit/Page Editor/Edit/My Items item from the core database.Soult
Thanks, Maras. Yes this works for me and ribbon is loaded normally now. Just wondered how in future debug such issues.What this query mean?Jaques
This is a standard Sitecore fast query which returns all items locked by the specified user.Soult
Trying to run query and see that my Sitecore.Context.ContentDatabase is null ? But on the web all is working fine.Jaques
Try to use Database.GetDatabase("master") instead of Sitecore.Context.ContentDatabaseSoult
D
3

I was experiencing the same issue in Sitecore 7 in page edit mode. I also verified the error occurred when clicking the "My Items" button in the content editor as well.

I found this post by Alex Shyba: http://sitecoreblog.alexshyba.com/2011/11/hidden-gem-of-sitecore-page-editor.html

His post suggests setting this setting in the web.config or better yet your include file:

<setting name="WebEdit.ShowNumberOfLockedItemsOnButton" value="false" />

This resolved the issue in the page editor for me and was clean and easy to implement. Hope this helps anyone else struggling with this as well.

Dody answered 21/8, 2013 at 20:3 Comment(0)
P
2

Using 7.1 this error started when I restored the databases from backups on another machine. I was able to resolve it by rebuilding the search index:

Desktop > Control Panel > Databases > Rebuild the Search Index

I also cleaned up the databases and rebuilt the link database, but those didn't seem to fix it.

Pedicel answered 2/7, 2014 at 21:17 Comment(1)
I had the same problem and Rebuild Search Index helped me.. Thanks.Octuple

© 2022 - 2024 — McMap. All rights reserved.