Creating Content Types from code

2025/10/03 8:15 AM

Hello,

We are in the process of migrating an old Kentico 11 site to Xperience by Kentico. Part of this is migratingĀ is creating Content Types from code and then creating pages for the newly created content types. We are creating a content type with:
dataClassInfo.ClassFormDefinition = form.GetXmlDefinition();
DataClassInfoProvider.SetDataClassInfo(dataClassInfo);

Where the form has a few default fields for pages like ContentItemDataID, ContentItemDataCommonDataID and ContentItemDataGUID.

We are not creating any other fields with PrimaryKey = true. We can see the newly created content type in the UI, but when we try to create a page of this type, we get an Exception on CreateWebPageBase - SubmitFirstStep:
Message: Value cannot be null. (Parameter 'identifier')

Exception type: System.ArgumentNullException````Stack trace:````at Kentico.Xperience.Admin.Base.Forms.FormComponentMapper.MapCore(IEnumerable1 formFields)+MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)````at Kentico.Xperience.Admin.Base.Forms.FormComponentMapper.Map(IEnumerable1 formFields) at Kentico.Xperience.Admin.Base.Forms.FormComponentsFormUtils.GetFormItems(Int32 dataClassId) at Kentico.Xperience.Admin.Websites.UIPages.Internal.CreateWebPageBase2.GetCombinedFormItems(CreateWebPageCreateCommandArguments args, Boolean useExistingValue, CancellationToken cancellationToken)````at Kentico.Xperience.Admin.Websites.UIPages.Internal.CreateWebPageBase2.SubmitSecondStep(CreateWebPageCreateCommandArguments args, CancellationToken cancellationToken) at Kentico.Xperience.Admin.Websites.UIPages.CreateWebPage.SubmitSecondStep(CreateWebPageCreateCommandArguments args, CancellationToken cancellationToken) at Kentico.Xperience.Admin.Websites.UIPages.Internal.CreateWebPageBase2.SubmitFirstStep(FormSubmissionCommandArguments args, CancellationToken cancellationToken)

Are we missing something in the creation of the content type? Is there another way to set the fields of the content type? How can we fix the problem?

Thank you in advance.


Environment

Tags:
Kentico Community Portal Content types v30.9.0 .NET

Answers

2025/10/03 8:11 PM
Accepted answer
  1. If you are upgrading from K11 to Xperience by Kentico, I'd strongly recommend using the Kentico Migration Tool which will handle the content type and content conversion for you, because it's one of the supported migration paths of the tool.
  2. If you are going to do this manually, I would recommend creating a content type through the Xperience administration UI to see what it generates in the database and the CI Repository. That way you can be sure you aren't missing fields or populating them incorrectly.
  3. You could experiment with using the community authored MCP server which can be used to generate or transform content types using an AI agent, which can analyze the XML form definition and follow that pattern to create a new content type.
  4. Or, you can wait until our planned update (currently planned for December) to natively integrate content type generation and transformation with AI for teams building Xperience solutions.

While dataClassInfo.ClassFormDefinition = form.GetXmlDefinition(); should work, it's not an officially supported way of creating content types. We don't make any guarantees about the database schema or editing interface created using these APIs.

2025/10/10 2:34 PM

For the next user with the same question:

The creation of Content Types succeeded by adding;

var contentTypeManager = Service.Resolve````();
var dataClass = contentTypeManager.Initialize(dataClassInfo);

Also, when you have created content types by code, you have to restart Kentico Admin to be able to work with the newly created content type.

To response this discussion, you have to login first.