Jeremy Davis
Jeremy Davis
Sitecore, C# and web development
Article printed from: https://blog.jermdavis.dev/posts/2021/recovering-from-a-packaging-mistake

Recovering from a packaging mistake

Published 30 August 2021
Sitecore ~3 min. read

A while back I got a support issue where a client's Content Editor was suddenly very broken. No UI – just a giant YSOD. It's turned out to be the sort of mistake which I could see happening to others, so here's some info on what happened and ways the problem can be resolved.

The report url copied!

A bunch of people were working on content entry and migration on a new instance of Sitecore, and suddenly they found Content Editor was broken. Users could log in to Sitecore, the desktop was fine and Experience Editor seemed ok, but as soon as they tried to go to Content Editor it would crash:

Broken Content Editor

Since that was blocking content creation work it was a Big Issue for the team. So off to the logs I went. The underlying exception was:

Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)   at Sitecore.Shell.Applications.ContentManager.ContentEditorPage.OnPreRender(EventArgs e)
   at System.Web.UI.Control.PreRenderRecursiveInternal()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Nested Exception

Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Sitecore.Buckets
   at Sitecore.Buckets.Commands.MakeTemplateBucketable.GetToolTip(CommandContext context, String tooltip)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.FillParamsFromCommand(CommandContext commandContext, RibbonCommandParams ribbonCommandParams)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.GetCommandParameters(Item controlItem, CommandContext commandContext)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderSmallCheckButton(HtmlTextWriter output, Item button, CommandContext commandContext)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderButton(HtmlTextWriter output, Item button, CommandContext commandContext)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunk(HtmlTextWriter output, Item chunk, CommandContext commandContext)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunk(HtmlTextWriter output, Item chunk, CommandContext commandContext, Boolean isContextual, String id)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunk(HtmlTextWriter output, Item chunk, CommandContext commandContext, Boolean isContextual)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderChunks(HtmlTextWriter output, Item strip, CommandContext commandContext, Boolean isContextual)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderStrips(HtmlTextWriter output, Item ribbon, Boolean isContextual, ListString visibleStripList)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.RenderStrips(HtmlTextWriter output, Item defaultRibbon, Item contextualRibbon, ListString visibleStripList)
   at Sitecore.Web.UI.WebControls.Ribbons.Ribbon.Render(HtmlTextWriter output)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at Sitecore.Web.HtmlUtil.RenderControl(Control ctl)
   at Sitecore.Shell.Applications.ContentManager.ContentEditorForm.UpdateRibbon(Item folder, Boolean isCurrentItemChanged, Boolean showEditor)
   at Sitecore.Shell.Applications.ContentManager.ContentEditorForm.Update()
   at Sitecore.Shell.Applications.ContentManager.ContentEditorForm.OnPreRendered(EventArgs e)

					

The issue url copied!

Thankfully there's a fair amount in Google about this error – it comes down to having an item in your content tree whose template does not exist. The Content Editor UI was not implemented to cope with this (fairly exceptional) situation. Hence the exception...

That crash is generally a bit of an issue when it happens with any old item – but it's particularly bad if the item in question happens to be "Home". The first item named "home" found under "/sitecore/content" is the one loaded automatically when Content Editor starts. So if this item is broken, then you're a bit stuffed, because Content Editor can't start up without encountering this crash.

The cause url copied!

After doing some digging, the cause of the issue here turned out to be that a whole tree of content had been imported from the "old website" instance of Sitecore. To people migrating content this made sense – it's easier to move stuff about and reformat it if it's in the same content tree as your new site. But unfortunately the editors in this case didn't realise that the new instance of Sitecore didn't have any of the templates from the old instance – so they'd accidentally created a tree of hundreds of items, none of which had valid templates.

So how can this be fixed? url copied!

Well the standard answer would be "install a package containing the right templates!" because if you do that, Content Editor will go back to being happy again immediately. But in this case that wasn't the right solution, because we didn't really want to have all the legacy content and templates in the shiny new instance of Sitecore.

The alternative is that you need to get rid of the item which is causing all the issues. Not having access to Content Editor makes that slightly less easy, but you still have choices. Maybe you have PowerShell Extensions installed? If so that can be used to call Remove-Item to perform the deletion. But if you don't, it's time to break out a classic old admin tool: DB Browser! You can access this from the /sitecore/admin/ url on your CM instance, and picking "DB Browser" from the menu:

DB Browser

As well as a useful tool, this image actually gives another clue to what's broken. When you look at a working item in DB Browser, it shows you the set of templates the item relies on to the right of the item's path:

Working Item

But in the case of our issue, (or similarly broken items) you'll see template(s) missing. In this case, since these items had no valid templates, that space to the right of the path was entirely empty:

Broken Item

But with this tool, it's an easy job to remove the broken item, by clicking the "Delete" button in the row of commands. With that done, Content Editor will sort itself out.

In my case, that was all that needed doing to resolve the issue – well, that and a bit of user education to ensure everyone understood what had gone wrong...

↑ Back to top