{"record":{"id":"70a399d279fb5525","repo":"elsa-workflows/elsa-core","slug":"the-document-declares-the-same-element-id-more-than-once","errorCode":null,"errorMessage":"The document declares the same element id more than once, which BPMN requires to be unique: {string.Join(\", \", duplicateIds)}. This is most often a subprocess nested inside another subprocess that reuses its parent's id. Reading or writing such a document cannot be done safely, so it is refused rather than attempted.","messagePattern":"The document declares the same element id more than once, which BPMN requires to be unique: (.+?)\\. This is most often a subprocess nested inside another subprocess that reuses its parent's id\\. Reading or writing such a document cannot be done safely, so it is refused rather than attempted\\.","errorType":"exception","errorClass":"BpmnDuplicateElementIdException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Bpmn.Interchange/Services/BpmnInterchangeDocumentService.cs","lineNumber":930,"sourceCode":"\n        var processIds = processList.Select(process => process.ProcessId);\n\n        var elementIds = processList\n            .Concat(bindings.OfType<BpmnWorkBinding.NestedProcess>().Select(nested => nested.Definition))\n            .SelectMany(process => process.Elements)\n            .Select(element => element.ElementId);\n\n        var duplicateIds = processIds\n            .Concat(elementIds)\n            .GroupBy(id => id, StringComparer.Ordinal)\n            .Where(group => group.Count() > 1)\n            .Select(group => group.Key)\n            .ToList();\n\n        if (duplicateIds.Count == 0)\n            return;\n\n        throw new BpmnDuplicateElementIdException(\n            $\"The document declares the same element id more than once, which BPMN requires to be unique: {string.Join(\", \", duplicateIds)}. \"\n            + \"This is most often a subprocess nested inside another subprocess that reuses its parent's id. Reading or writing such a document \"\n            + \"cannot be done safely, so it is refused rather than attempted.\",\n            duplicateIds);\n    }\n\n    /// <summary>\n    /// Refuses the definition, naming the missing capability and the offending element ids, when it or any process\n    /// nested inside it needs a host capability <see cref=\"DeclaredHostCapabilities\"/> does not cover.\n    /// </summary>\n    private static void EnsureCapabilitiesSatisfied(BpmnProcessDefinition definition, IReadOnlyList<BpmnWorkBinding> bindings) =>\n        EnsureCapabilitiesSatisfied(definition, bindings, DeclaredHostCapabilities);\n\n    /// <summary>\n    /// Refuses the definition, naming the missing capability and the offending element ids, when it or any process\n    /// nested inside it needs a host capability <paramref name=\"available\"/> does not cover.\n    /// </summary>\n    /// <remarks>","sourceCodeStart":912,"sourceCodeEnd":948,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Bpmn.Interchange/Services/BpmnInterchangeDocumentService.cs#L912-L948","documentation":"BpmnInterchangeDocumentService validates that every element id in a BPMN document is unique, as the BPMN spec requires. When duplicates are found it throws BpmnDuplicateElementIdException listing the duplicated ids, refusing to read or write the document because doing so safely is impossible. The most common cause is a subprocess nested inside another subprocess that reuses its parent's id.","triggerScenarios":"Calling ImportCoreAsync or ImportDocumentAsync on a document where two or more elements share the same id (duplicate groupings found by EnsureElementIdsUnique).","commonSituations":"Copy-pasting a subprocess within a diagram without regenerating ids; model round-trips that collapse id namespaces; hand-edited XML reusing ids.","solutions":["Open the file and rename the duplicated ids listed in the exception so each is unique (most often the nested subprocess).","Re-export the diagram from the modeling tool after fixing duplicate ids, rather than hand-editing XML.","If duplicates come from generated code/templates, ensure id generation uses globally unique values per document."],"exampleFix":"<!-- before -->\n<process id=\"Order\"/>\n  <subProcess id=\"Order\"/>\n<!-- after -->\n<process id=\"Order\"/>\n  <subProcess id=\"OrderBody\"/>","handlingStrategy":"validation","validationCode":"var dupes = doc.Descendants().Attributes(\"id\").GroupBy(a => a.Value).Where(g => g.Count() > 1).Select(g => g.Key).ToList();\nif (dupes.Count > 0) throw new InvalidOperationException($\"Duplicate BPMN ids: {string.Join(\", \", dupes)}\");","typeGuard":null,"tryCatchPattern":"try { await svc.ImportDocumentAsync(stream); }\ncatch (BpmnDuplicateElementIdException ex) { log.LogError(\"Duplicate ids: {Ids}\", ex.DuplicateIds); return ValidationFailure(ex.Message); }","preventionTips":["Regenerate ids when copy-pasting subprocesses in the modeler.","Add a pre-import lint that checks id uniqueness.","Avoid hand-editing BPMN XML; re-export from the tool."],"tags":["bpmn","validation","duplicate-ids"],"backgroundTag":"schema-validation-failed","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}