{"record":{"id":"6e669de809c4d465","repo":"OrchardCMS/OrchardCore","slug":"there-is-already-another-index-with-the-same-name","errorCode":null,"errorMessage":"There is already another index with the same name.","messagePattern":"There is already another index with the same name\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Indexing.Core/DefaultIndexProfileStore.cs","lineNumber":119,"sourceCode":"    public ValueTask CreateAsync(IndexProfile indexProfile)\n        => UpdateAsync(indexProfile);\n\n    public async ValueTask UpdateAsync(IndexProfile indexProfile)\n    {\n        ArgumentNullException.ThrowIfNull(indexProfile);\n\n        if (string.IsNullOrEmpty(indexProfile.Id))\n        {\n            indexProfile.Id = IdGenerator.GenerateId();\n        }\n\n        var exists = await _session.QueryIndex<IndexProfileIndex>()\n            .Where(x => x.IndexName == indexProfile.IndexName && x.ProviderName == indexProfile.ProviderName && x.IndexProfileId != indexProfile.Id)\n            .FirstOrDefaultAsync();\n\n        if (exists is not null)\n        {\n            throw new InvalidOperationException(\"There is already another index with the same name.\");\n        }\n\n        var existsByName = await _session.QueryIndex<IndexProfileIndex>()\n            .Where(x => x.Name == indexProfile.Name && x.IndexProfileId != indexProfile.Id)\n            .FirstOrDefaultAsync();\n\n        if (existsByName is not null)\n        {\n            throw new InvalidOperationException(\"There is already another index with the same name.\");\n        }\n\n        await _session.SaveAsync(indexProfile, checkConcurrency: true);\n    }\n\n    private IQuery<IndexProfile, IndexProfileIndex> BuildQuery(QueryContext context)\n    {\n        var query = _session.Query<IndexProfile, IndexProfileIndex>();\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Indexing.Core/DefaultIndexProfileStore.cs#L101-L137","documentation":"DefaultIndexProfileStore.UpdateAsync enforces uniqueness of index profiles before saving. It throws InvalidOperationException if another profile with the same IndexName + ProviderName already exists (different Id), and also checks for a duplicate Name. This prevents two index profiles competing for the same index in the search/indexing system.","triggerScenarios":"Calling IIndexProfileStore.UpdateAsync with an index profile whose (IndexName, ProviderName) pair matches an existing profile with a different Id - e.g. importing a recipe or JSON step that re-declares an existing index, or renaming a profile's Name/IndexName to collide.","commonSituations":"Recipe re-runs or migrations that create index profiles without an existence check; two admins creating the same index name concurrently; copy-pasting an index profile definition and only changing the display name; importing settings from another site.","solutions":["Before updating, query the store for an existing profile with the same IndexName/ProviderName and update that record instead of creating a new one.","Use a unique IndexName (e.g. suffix with tenant/scope) for the new profile.","In recipes/migrations, guard the creation step with an existence check or make the step idempotent.","Catch InvalidOperationException around UpdateAsync and surface a duplicate-name validation error in the admin UI."],"exampleFix":"// before\nawait indexProfileStore.UpdateAsync(new IndexProfile { IndexName = \"ArticlesIndex\", ProviderName = \"Lucene\", ... });\n// after\nvar existing = (await indexProfileStore.ListAsync())\n    .FirstOrDefault(p => p.IndexName == \"ArticlesIndex\" && p.ProviderName == \"Lucene\");\nif (existing is null)\n{\n    await indexProfileStore.UpdateAsync(new IndexProfile { IndexName = \"ArticlesIndex\", ProviderName = \"Lucene\", ... });\n}\nelse\n{\n    existing.Source = ...; // mutate the existing profile instead\n    await indexProfileStore.UpdateAsync(existing);\n}","handlingStrategy":"try-catch","validationCode":"var duplicate = (await indexProfileStore.ListAsync())\n    .Any(p => p.IndexName == profile.IndexName && p.ProviderName == profile.ProviderName && p.Id != profile.Id);\nif (duplicate)\n{\n    throw new InvalidOperationException($\"An index profile named '{profile.IndexName}' ({profile.ProviderName}) already exists.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await indexProfileStore.UpdateAsync(profile);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"another index with the same name\"))\n{\n    modelState.AddModelError(nameof(profile.IndexName), \"An index with this name already exists.\");\n}","preventionTips":["Make recipe/migration index-creation steps idempotent by checking existence first.","Derive IndexName from a tenant/scope-prefixed convention to avoid collisions across sites.","Handle duplicate-name validation in admin editors before calling UpdateAsync.","Never rename an index profile's IndexName to a name already used by another profile with the same provider."],"tags":["indexing","duplicate-name","uniqueness-constraint"],"backgroundTag":"record-already-exists","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}