OrchardCMS/OrchardCore · error · InvalidOperationException
Unable to create a unique index name for
Error message
Unable to create a unique index name for '{indexName}' after 50 attempts. What it means
During AzureAISearchIndexSettingsMigrations.UpdateFrom1, legacy index names are migrated to index profiles; when the generated name collides with an existing profile the code appends an incrementing counter. If no unique name is found after 50 attempts it throws InvalidOperationException to abort the migration safely rather than overwrite an existing profile.
Solutions
- Rename or delete conflicting index profiles so the migrated name is free, then re-run the migration.
- Roll back the migration, consolidate duplicate indexes, and update again.
- Inspect the index profiles table for names like '<indexName>N' to identify the collisions.
- Back up the database before retrying the migration.
Defensive patterns
Strategy: try-catch
Validate before calling
// Detect collisions before migrating:
var conflicts = profiles.Where(p => Regex.IsMatch(p.Name, $"^{Regex.Escape(baseName)}\\d*$"));
if (conflicts.Count() > 1) logger.LogWarning("Index name collisions likely for {Base}", baseName); Try / catch
try { await migration.UpdateFrom1Async(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("unique index name"))
{
logger.LogError(ex, "AzureAI index migration blocked by name collisions; rename conflicting profiles manually");
} Prevention
- Back up the database before running migrations
- Review existing index profile names before upgrading
- Avoid manually creating profiles named like legacy search indexes
- Test the upgrade on a staging copy first
When it happens
Trigger: Running the AzureAI migration on a system that already contains many index profiles named '<indexName>0'...'<indexName>50'; duplicate legacy index names across tenants; repeated migration runs creating sequential collisions.
Common situations: Upgrading an Orchard Core site where Azure AI Search index profiles were manually created with names matching legacy search indexes; sites with a large number of similarly-named indexes.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- The index does not have a key field.
- Unsupported Azure AI Search vector algorithm kind.
- The type ' ' is not support by Azure AI Search
- Unable to create a safe index prefix for AI Search…
- The ' ' field in ' ' part was defined without a specified…
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/0a5c0c834dea057f.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore.Modules/OrchardCore.AzureAI/Migrations/AzureAISearchIndexSettingsMigrations.cs:143
indexProfile.IndexFullName = indexNameProvider.GetFullIndexName(indexName);
indexProfile.Name = indexName;
var counter = 1;
var properties = indexObject.Value[nameof(indexProfile.Properties)]?.AsObject();
if (properties is not null && properties.Count > 0)
{
indexProfile.Properties = properties.Clone();
}
while (await indexProfileManager.FindByNameAsync(indexProfile.Name) is not null)
{
indexProfile.Name = $"{indexName}{counter++}";
if (counter > 50)
{
throw new InvalidOperationException($"Unable to create a unique index name for '{indexName}' after 50 attempts.");
}
}
var id = indexObject.Value["Id"]?.GetValue<string>();
if (!string.IsNullOrEmpty(id))
{
indexProfile.Id = id;
}
var metadata = indexProfile.GetOrCreate<ContentIndexMetadata>();
if (string.IsNullOrEmpty(metadata.Culture))
{
metadata.Culture = indexObject.Value[nameof(metadata.Culture)]?.GetValue<string>();
}
var indexLatest = indexObject.Value[nameof(metadata.IndexLatest)]?.GetValue<bool>();View on GitHub (pinned to 4306c0717f)