Treeprovider.CopyNode throws Exception: TreeNode.InsertAsNewCultureVersionInternal

Kenny Deblaere asked on May 11, 2017 12:20


I'm trying to copy a node to another path. This works when I'm doing this for one culture. Not having a translation.

But when I add a translated version I get the Exception: TreeNode.InsertAsNewCultureVersionInternal. "[TreeNode.InsertAsNewCultureVersionInternal]: The new culture version cannot be under different parent node than original node"

I'm using Kentico 9.0.50.

I have no clue why I get this, or this error occures.

Kind regards


Correct Answer

Kenny Deblaere answered on May 11, 2017 15:30

Hi Juraj

Thank you for your answer. I've done a workaround, but have an upgrade in the near future.

My workaround however, is a bit different:

var tree = new TreeProvider(MembershipContext.AuthenticatedUser);
var originalNodeContainer = tree.SelectNode(node.NodeParentID);
if(originalNode != null){
    var newNode = tree.CopyNode(node, originalNodeContainer, true);
    tree.MoveNode(newNode, nodeContainer, true);

This does also the trick, and I guess there are less operations?

Kind regards


0 votesVote for this answer Unmark Correct answer

Recent Answers

Juraj Ondrus answered on May 11, 2017 15:18

Hi Kenny,
Regrettably, there was a bug in Kentico 9. It was fixed in Kentico 10.
So, option no. 1 is the upgrade to Kentico 10.
Option no. 2 is a workaround and use the action context like this:

using (new DocumentActionContext { ResetChanges = true })
    foreach (var sourceChildNode in sourceNode.Children)
        var node = DocumentHelper.CopyDocument(sourceChildNode, documentEventArgs.Node, true, tree);
1 votesVote for this answer Mark as a Correct answer

Lars Middleton answered on April 9, 2018 18:09

Hi, Juraj (and Kenny).

I am updating here to help others, since it helped us.

The workaround in this post solved the same issue in a Kentico 10 site for us. So unfortunately, a Kentico 10 upgrade did NOT solve the bug in our case.

Details: we use a handler on DocumentEvents.Insert.After which copies and inserts some child documents when a certain parent document type is inserted in the CMS tree.

The handler worked in Kentico version 8.1, but after upgrade to Kentico 10.0.50 an exception was thrown by: var copy = DocumentHelper.CopyDocument(node, targetNode, true, treeProvider);

Wrapping the entire block of code per Juraj's workaround solved the issue:

using (new DocumentActionContext { ResetChanges = true })
    (...our existing code here...)

The partial stack trace (to increase findability of this post) is:

An error occurred when saving data. Please see event log for more details.
Message: The new culture version cannot be under different parent node than original node

Exception type: System.Exception
Stack trace:
at CMS.DocumentEngine.TreeNode.InsertAsNewCultureVersionInternal(String cultureCode)
at CMS.DocumentEngine.TreeNode.InsertAsNewCultureVersion(String cultureCode, Boolean useDocumentHelper)
at CMS.DocumentEngine.DocumentCopier.InsertNewDocumentCultureVersion(TreeNode targetCultureNode)
at CMS.DocumentEngine.DocumentCopier.CopyCultureVersion(TreeNode sourceCultureNode, TreeNode firstCopiedCultureNode)
at CMS.DocumentEngine.DocumentWithVersionsCopier.CopyCultureVersion(TreeNode sourceCultureNode, TreeNode firstCopiedCultureNode)
at CMS.DocumentEngine.DocumentCopier.CopyCultureVersions()
at CMS.DocumentEngine.DocumentCopier.Copy()
at CMS.DocumentEngine.DocumentHelper.CopyDocument(TreeNode node, TreeNode target, Boolean includeChildNodes, TreeProvider tree)
(... more lines below from our custom code components...)

Cheers, Laurence

0 votesVote for this answer Mark as a Correct answer

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