{"record":{"id":"c1ca42876a691320","repo":"microsoft/aspire","slug":"aspireradius043-secret-store-store-name-declares-the-key-key","errorCode":"ASPIRERADIUS043","errorMessage":"Secret store '{store.Name}' declares the key '{key}' more than once. Diagnostic: ASPIRERADIUS043.","messagePattern":"Secret store '(.+?)' declares the key '(.+?)' more than once\\. Diagnostic: ASPIRERADIUS043\\.","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Radius/Secrets/RadiusSecretStoreValidation.cs","lineNumber":146,"sourceCode":"                \"(WithData, WithExistingSecret, or WithSealedSecret); it declares \" +\n                $\"{population.DeclaredModeCount}. Diagnostic: ASPIRERADIUS041.\");\n        }\n\n        var declaredKeys = population.HasInlineData\n            ? population.Data.Keys.ToList()\n            : population.Keys;\n\n        // ASPIRERADIUS043 — duplicate keys. Inline keys are rejected as they are added (the data\n        // dictionary rejects a duplicate via RadiusSecretStoreDataBuilder.Add), so only the\n        // existing/sealed key list needs a duplicate scan here.\n        if (population.IsSecretReference)\n        {\n            var seen = new HashSet<string>(StringComparer.Ordinal);\n            foreach (var key in population.Keys)\n            {\n                if (!seen.Add(key))\n                {\n                    throw new InvalidOperationException(\n                        $\"Secret store '{store.Name}' declares the key '{key}' more than once. \" +\n                        \"Diagnostic: ASPIRERADIUS043.\");\n                }\n            }\n        }\n\n        // ASPIRERADIUS040 — type-aware required keys.\n        foreach (var required in store.Type.RequiredKeys())\n        {\n            if (!declaredKeys.Contains(required, StringComparer.Ordinal))\n            {\n                throw new InvalidOperationException(\n                    $\"Secret store '{store.Name}' of type '{store.Type.ToRadiusTypeString()}' is missing \" +\n                    $\"the required key '{required}'. Diagnostic: ASPIRERADIUS040.\");\n            }\n        }\n\n        // ASPIRERADIUS042 / ASPIRERADIUS047 — inline bindings must be secret and use valid encoding.","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Radius/Secrets/RadiusSecretStoreValidation.cs#L128-L164","documentation":"ASPIRERADIUS043 duplicate-key detection in ValidateStore: population.Keys is scanned with an ordinal HashSet, and any key appearing more than once throws. This is the model-level gate that backs the duplicate rejection in the Add API; it catches duplicates declared through any path.","triggerScenarios":"A store's population keys list contains the same key string twice (ordinal comparison), e.g. two existing/sealed key declarations with identical names, reaching validation.","commonSituations":"Merging two key lists that overlap; programmatic generation of keys from config that repeats; case-only differences avoided here because comparison is ordinal, so 'Key' vs 'key' are distinct but exact duplicates fail.","solutions":["Remove the duplicate key declaration so each key appears once.","Rename one of the conflicting keys.","Deduplicate before registering (e.g. Distinct(StringComparer.Ordinal))."],"exampleFix":"// before\nstore.WithExistingSecret(..., keys: [\"a\", \"a\"]);\n// after\nstore.WithExistingSecret(..., keys: [\"a\"]);","handlingStrategy":"validation","validationCode":"bool hasDuplicates = populationKeys.Distinct(StringComparer.Ordinal).Count() != populationKeys.Count();","typeGuard":null,"tryCatchPattern":"try { /* validation runs */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ASPIRERADIUS043\")) { /* remove/rename the duplicated key */ }","preventionTips":["Deduplicate generated key lists with Distinct(StringComparer.Ordinal) before registering","Track declared keys in a HashSet while building the population","Review merges of two key lists for overlaps"],"tags":["duplicate-key","validation","radius"],"backgroundTag":"conflicting-config-options","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}