{"record":{"id":"195f1b62a3a13205","repo":"dotnet/aspnetcore","slug":"more-than-one-sibling-has-the-same-key-value-ke","errorCode":null,"errorMessage":"More than one sibling has the same key value, '{key}'. Key values must be unique.","messagePattern":"More than one sibling has the same key value, '(.+?)'\\. Key values must be unique\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs","lineNumber":386,"sourceCode":"\n            newStartIndex = NextSiblingIndex(frame, newStartIndex);\n        }\n\n        return result;\n    }\n\n    private static void ThrowExceptionForDuplicateKey(object key, in RenderTreeFrame frame)\n    {\n        switch (frame.FrameTypeField)\n        {\n            case RenderTreeFrameType.Component:\n                throw new InvalidOperationException($\"More than one sibling of component '{frame.ComponentTypeField}' has the same key value, '{key}'. Key values must be unique.\");\n\n            case RenderTreeFrameType.Element:\n                throw new InvalidOperationException($\"More than one sibling of element '{frame.ElementNameField}' has the same key value, '{key}'. Key values must be unique.\");\n\n            default:\n                throw new InvalidOperationException($\"More than one sibling has the same key value, '{key}'. Key values must be unique.\");\n        }\n    }\n\n    private static object KeyValue(ref RenderTreeFrame frame)\n    {\n        switch (frame.FrameTypeField)\n        {\n            case RenderTreeFrameType.Element:\n                return frame.ElementKeyField;\n            case RenderTreeFrameType.Component:\n                return frame.ComponentKeyField;\n            default:\n                return null;\n        }\n    }\n\n    // Handles the diff for attribute nodes only - this invariant is enforced by the caller.\n    //","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/RenderTree/RenderTreeDiffBuilder.cs#L368-L404","documentation":"When RenderTreeDiffBuilder encounters duplicate keys among sibling frames that are neither Component nor Element type (falling into the default case of ThrowExceptionForDuplicateKey), it throws a generic InvalidOperationException. This covers edge cases in manual RenderTreeBuilder usage where non-element/non-component frames carry duplicate keys.","triggerScenarios":"Using RenderTreeBuilder.SetKey on frames that are not Element or Component (though SetKey itself would throw a different error), or internal framework code that assigns keys to non-standard frame types. This is primarily an internal/edge-case error that most developers will never encounter directly.","commonSituations":"Custom RenderTreeBuilder code that manipulates frame keys directly; framework-level bugs in rendering; extremely unusual manual tree construction scenarios.","solutions":["Review any custom RenderTreeBuilder code for incorrect key assignment on non-element/non-component frames.","Ensure @key is only used on elements and components, which is the normal Razor behavior.","If this occurs in framework code without custom RenderTreeBuilder usage, file a Blazor issue.","Avoid using SetKey outside the normal element/component scope."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// For manual RenderTreeBuilder code, validate keys on non-standard frames\nstatic void AssertUniqueKeysInFrames(ArrayBuilder<RenderTreeFrame> entries, int start, int end)\n{\n    var seen = new HashSet<object>();\n    for (int i = start; i < end; i++)\n    {\n        object? key = entries.Buffer[i].FrameTypeField switch\n        {\n            RenderTreeFrameType.Element => entries.Buffer[i].ElementKeyField,\n            RenderTreeFrameType.Component => entries.Buffer[i].ComponentKeyField,\n            _ => null\n        };\n        if (key != null && !seen.Add(key))\n            throw new InvalidOperationException($\"Duplicate key: {key}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use @key on elements and components.","In custom RenderTreeBuilder code, track keys and assert uniqueness before committing the batch.","Report framework bugs if this error appears without custom RenderTreeBuilder usage.","Avoid manual key assignment on non-element/non-component frames."],"tags":["blazor","key","diffing","rendertreebuilder","internal"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}