NullReferenceException changing language

Peter Wooster asked on October 28, 2020 16:30

A live Kentico 8.2 project I'm working on gets a NullReferenceException when I switch languages (English to French) on certain pages (French page absent). The exception is on the following line: <body class="<%=BodyClass%>" <%=BodyParameters%>> in CMS\CMSPages\PortalTemplate.aspx

The stack trace is:

[NullReferenceException: Object reference not set to an instance of an object.] ASP.cmsvirtualfiles_templates_shared__vg_d26b0137_a9e5_4629_b880_311bb1af0bbb_masterpagetemplate_fr_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\inetpub\wwwroot....\CMS\CMSVirtualFiles\Templates\Shared=vg=d26b0137-a9e5-4629-b880-311bb1af0bbb\MasterPageTemplate_fr.ascx:27 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +275 CMS.ExtendedControls.AbstractUserControl.Render(HtmlTextWriter writer) +196 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +79 CMS.PortalControls.CMSPagePlaceholder.Render(HtmlTextWriter writer) +718 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +79 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +168 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +11659742 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +46 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +79 System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +52 ASP.cmspages_portaltemplate_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\inetpub\wwwroot.....\CMS\CMSPages\PortalTemplate.aspx:11 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +275 CMS.UIControls.ContentPage.Render(HtmlTextWriter writer) +364 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +79 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4238

The French page does not exist, but the English one does. Is there a way to prevent this attempt to change languages for these pages?

Attempting to access the French page in the Pages app gives:

"The page does not exist in the current culture. You can create a new culture version of the page."

Attempting to add the missing French page either by creating a new page or copying the English page fails with:

Caused exception: Cannot insert duplicate key row in object 'dbo.View_CMS_Tree_Joined_Regular' with unique index 'IX_View_CMS_Tree_Joined_Regular_NodeSiteID_DocumentCulture_NodeID'. The duplicate key value is (1, fr-CA, 9917). The statement has been terminated.

Correct Answer

Dmitry Bastron answered on October 29, 2020 00:28

You are right, it's likely that someone has just deleted the record directly from FindATests SQL table directly, but that isn't the right way. If you do so, you need to be aware of other info that needs deleting as well. Please refer to SQL table structure of CMS tree here.

I guess if you delete a record for fr-CA language for this page from CMS_Document table that should be enough to be able to create it again without seeing this error.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Wooster answered on October 28, 2020 18:04

This appears to be caused by a custom table that is joined to the Tree, but is missing the French record for some nodes.

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on October 28, 2020 23:38

Hi Peter,

Could you check in the database if that french page (I assume you are talking about Canadian French based on your error message)? The following SQL query should show you all culture versions that exist for your page:

SELECT *
FROM View_CMS_Tree_Joined t
WHERE t.NodeID = 9917
0 votesVote for this answer Mark as a Correct answer

Peter Wooster answered on October 29, 2020 00:18 (last edited on October 29, 2020 00:20)

Thanks for the reply, I did something similar to find all the broken tests.

The problem is that the fr-CA page exists for Node 9917, but the associated custom FindATests record does not. The DocumentForeignKeyValue field points to the missing record.

On our QA system this is correct, but fails on the Live system and my local test site.

I need to prevent attempts to change the language on these records, and find a way to fix them. I can probably run a query to see if there is a French FindATests record and hide the language choice button if it's not there. I didn't develop this and have no idea how it got this screwed up on the Live system, I suspect someone deleted records.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.