Troubleshooting content APIs

Current version: 10.3

This topic contains troubleshooting information for common issues Sitecore developers experience when using content APIs.

Could not find configuration node

You might see messages such as the following in the browser if you attempt to use the Sitecore.Configuration.Factory.GetDatabase() method to access a database that does not exist, or you do not enter the database name in the same character case as its configuration in web.config:

System.InvalidOperationException: Could not find configuration node

Ensure that the value passed as the first parameter to the Sitecore.Configuration.Factory.GetDatabase() method matches the ID attribute of the appropriate /configuration/sitecore/databases/database element in web.config.

Object reference not set to an instance of an object

You might see messages such as the following in the browser if you attempt to access an item that does not exist, or has not been published:

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

Ensure that the ID or path specified for the item is correct, that the code accesses the correct database, that the item exists in that database, and that the context user has the item:read access right to the item. You might need to publish the item or its data template, or use a security user switcher or security disabler.

Item is not in editing mode

You might see messages such as the following in the browser if you attempt to update an item without placing it in editing mode:

Sitecore.Exceptions.EditingNotAllowedException: Item is not in editing mode

We recommend that you provide the context user with the appropriate access rights instead of using a security user switcher or a security disabler. The code examples in this document do not use a security user switcher or security disabler. This requires that the context user has the required access rights in order for the logic to succeed.

The current user does not have write access to this Item

You might see messages such as the following in the browser if you attempt to update an item that the context user does not have the item:write security access right to:

System.UnauthorizedAccessException: The current user does not have write access to this item

Ensure that the context user has the item:write access right to the item. You might need to use a security user switcher or security disabler.

Add access required

You might see messages such as the following in the browser if you attempt to add an item under an item to which the context user does not have permission to access the item:

Sitecore.Exceptions.AccessDeniedException: AddFromTemplate - Add access required

Ensure that the context user has the item:create access right to the parent item. You might need to use a security user switcher or security disabler. For more information about using a security user switcher or security disabler, see the section How to Resolve Item Access Rights.

When you create an item, Sitecore automatically places the first version in the context language in the initial state of the default workflow specified in the standard values of the item’s data template.

To update the workflow state of an item, you can refer to the following methods:

  • Sitecore.Workflows.Simple.Workflow.Start

  • Sitecore.Workflows.Simple.Workflow.Execute

Do you have some feedback for us?

If you have suggestions for improving this article,