6

The page crashes and gives "Length cannot be less than zero." when i insert a Sitecore link in the RTE.

It happens as soon as you visit the specefic page on the site. The error is not thrown when you are browsing the page from the Experience editor.

Has anyone experienced this kind of behaviour before?

Stack trace

[ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length]
   System.String.Substring(Int32 startIndex, Int32 length) +14415580
   Sitecore.Pipelines.RenderField.ProtectedImageLinkRenderer.ReplaceReference(String tagHtml, String urlAttribute) +300
   Sitecore.Pipelines.RenderField.ProtectedImageLinkRenderer.HashReferences(String renderedText, String tagName, String urlAttribute) +802
   Sitecore.Pipelines.RenderField.ProtectedImageLinkRenderer.Process(RenderFieldArgs args) +121
   (Object , Object[] ) +71
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +484
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
   Sitecore.Web.UI.WebControls.FieldRenderer.RenderField() +942
   Sitecore.Web.UI.WebControls.FieldControl.DoRender(HtmlTextWriter output) +255
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   Sitecore.Web.UI.WebControls.Sublayout.DoRender(HtmlTextWriter output) +49
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   Sitecore.Web.UI.WebControls.Placeholder.DoRender(HtmlTextWriter output) +134
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   Sitecore.Web.UI.WebControls.Sublayout.DoRender(HtmlTextWriter output) +49
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   Sitecore.Web.UI.WebControls.Placeholder.DoRender(HtmlTextWriter output) +134
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   Sitecore.Web.UI.WebControls.Sublayout.DoRender(HtmlTextWriter output) +49
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   Sitecore.Web.UI.WebControls.Placeholder.DoRender(HtmlTextWriter output) +134
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +11868329
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +47
   Sitecore.Web.FormAdapter.Render(HtmlTextWriter writer) +76
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +116
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +50
   ASP.layouts_linak_site_linak_html_body_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\28c1c560\ff0e1871\App_Web_iitpqjv4.0.cs:0
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +263
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   Sitecore.Web.UI.WebControls.Sublayout.DoRender(HtmlTextWriter output) +49
   Sitecore.Web.UI.WebControl.Render(HtmlTextWriter output) +345
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.Page.Render(HtmlTextWriter writer) +39
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3499
11
  • Do you have a stack trace or log or anything that would prevent us from guessing? – Gatogordo Nov 10 '16 at 10:19
  • do you have also images on your rich text? if yes can you remove images and try again – Vlad Iobagiu Nov 10 '16 at 10:30
  • It does make a difference if i have a image or not in the RTE. It still produces the error – Mathias Hove Nov 10 '16 at 11:05
  • can you please add a link code how it stored in RTE (something like <a href="/~/...z=Z">). And which SC version do you use? I saw such error once it was caused by wrong case of the z=z parameter. – Daniil Nov 10 '16 at 12:29
  • The link itself does not contain any z=z parameters. example "<a href="-/media/3d955bcdb03c45dcafad14d2813ad2bc.ashx">pdf</a>" The version of sitecore is 8.2. – Mathias Hove Nov 10 '16 at 12:57
5

While investigating this issue when I hit it during an upgrade, my debugging discovered that this was caused by a bug in the PortectedImageLinkRenderer class which cannot handle empty <a> tags. In my scenario, I had some HTML in the rich text field as follows:

<a>Some Text Here</a>

When the pipeline tried to process the 'HREF' tag of the anchor, it couldn't find it but the algorithm didn't safely handle this scenario, leading to the exception above.

I was able to patch in my own version of the ProtectedImageLinkRenderer which handled the empty tags and it resolved the issue. @Velict, you may wish to do the same if you need to have empty tags. Alternatively, you can add an HREF tag to your empty anchors and it will work.

I have also submitted a support ticket to Sitecore, referencing 8.2 update 2, to request an official patch. I'll update this answer if I hear back.

UPDATE: I don't have an official patch yet, but my debugging to help the support desk did uncover that this requires a very specific combination. The HTML must have an empty tag and ALSO a media link that needs to be processed. Either of them on their own is fine.

The following HTML example can reproduce the issue in a default Sitecore 8.2 u2 installation by editing the 'Text' field of the default Home node:

<p><a>Empty HREF</a></p>
<p><a href="-/media/094AED0302E7486880CB19926661FB77.ashx">Media link</a></p>

UPDATE (2017-03-01): I have received an official support patch for 8.2update 2 for this from Sitecore: https://github.com/SitecoreSupport/Sitecore.Support.149817/releases/tag/8.2.2.0

3
  • Sitecore Support seems to have taken that repo down. You should be able to get the patch directly from Sitecore Support, however. – Ed Schwehm Aug 14 '17 at 17:48
  • Thank you. Saved me and the client in a Friday afternoon :) – Alireza Oct 2 '17 at 6:56
  • This is excellent! By removing the empty <a> tag, the issue was fixed. – scubaFun Dec 1 '17 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.