The following reusable field schemas do not exist
Some web page types inherit from a reusable schema, some do not. The below query for my sitemap throws the error "The following reusable field schemas do not exist 'BasePage'". I ran codegen for the content types and reusable schema types. I am not sure why I am getting this error.
var b = new ContentItemQueryBuilder()
.ForContentTypes(c => c
.OfReusableSchema(IBasePage.REUSABLE_FIELD_SCHEMA_NAME)
.ForWebsite(website.WebsiteChannelName))
.InLanguage(preferredLanguageRetriever.Get());
Environment
Xperience by Kentico version: [30.3.1]
.NET version: [8]
Execution environment: [local]
Link to relevant Xperience by Kentico documentation
Answers
I'm not sure what is causing your error.
This is the same implementation I use in the Kentico Community Portal, which works.
var b = new ContentItemQueryBuilder()
.ForContentTypes(c => c
.OfReusableSchema(IWebPageMeta.REUSABLE_FIELD_SCHEMA_NAME)
.ForWebsite(website.WebsiteChannelName))
.InLanguage(PortalWebSiteChannel.DEFAULT_LANGUAGE);
Possible causes of your problem.
- You are querying a different database than the one you are using the generate your content types.
- You have a build error so your code generation isn't actually running or your generated code is out of date compared to what is in the database.
- Your use of the
IContentQueryExecutor
is causing the problem, not the query you've constructed.
I am using Xperience by Kentico 30.3.1. When I run dotnet run --no-build -- --kxp-codegen --type "ReusableFieldSchemas" --location "../MVC.Entities//" --namespace "MVC.Entities"
it generates a code file like below, removing the "." from MVC.BasePage
public const string REUSABLE_FIELD_SCHEMA_NAME = "MVCBasePage";
Replacing the "." fixes the problem
Generating the ReusableFieldSchemas again, removes the "."
It appears to be a bug. I fixed the issue for now by avoiding calling .OfReusableSchema and just using .OfContentType and listing all of the webpage content types that use this schema.
Update: This is caused by a bug in reusable field schema name validation, not code generation. This will be fixed in an upcoming hotfix.
Reusable field schemas should not generate with a REUSABLE_FIELD_SCHEMA_NAME
that includes a .
. Additionally, the code name of the schema, which is the value this field refers to, should not have a .
in it.
Just try this out on a new Dancing Goat project. Also look at the Kentico Community Portal.
using System;
using System.Collections.Generic;
namespace Kentico.Community.Portal.Core.Content
{
/// <summary>
/// Defines a contract for content types with the <see cref="IWebPageMeta"/> reusable schema assigned.
/// </summary>
public interface IWebPageMeta
{
/// <summary>
/// Code name of the reusable field schema.
/// </summary>
public const string REUSABLE_FIELD_SCHEMA_NAME = "WebPageMeta";
// ....
}
}
The problem is that you are allowed to use a .
character in the reusable field schema codename field. It doesn't appear to be correctly validated in the form field in the admin UI.
Remove the .
from your schema name, regenerate your code, and try again.
To answer this question, you have to login first.