Skip to content

Fix duplicate keys in aspire config set with colon notation#14921

Merged
JamesNK merged 2 commits intorelease/13.2from
jamesnk/fix-duplicate-config-keys
Mar 4, 2026
Merged

Fix duplicate keys in aspire config set with colon notation#14921
JamesNK merged 2 commits intorelease/13.2from
jamesnk/fix-duplicate-config-keys

Conversation

@JamesNK
Copy link
Copy Markdown
Member

@JamesNK JamesNK commented Mar 4, 2026

Description

Fix duplicate key errors in aspire config commands when users mix colon (:) and dot (.) notation for the same configuration key.

Problem: Running aspire config set features:polyglotSupportEnabled true followed by aspire config set features.polyglotSupportEnabled true creates both a flat "features:polyglotSupportEnabled" root key and a nested "features": { "polyglotSupportEnabled": ... } object in the settings JSON. When the configuration is later loaded, .NET's JSON configuration parser throws FormatException: A duplicate key was found, crashing the CLI.

Fix:

  • Normalize colon-separated keys to dot notation in SetNestedValue, DeleteNestedValue, and FlattenJsonObject so both separators produce the same nested JSON.
  • Proactively normalize already-corrupted settings files (converting flat colon keys to nested objects) before loading them in ConfigurationHelper.RegisterSettingsFiles.
  • Extract shared WriteSettingsFile/WriteSettingsFileAsync helpers to ConfigurationHelper to centralize settings file serialization.

Fixes #14795

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Normalize colon-separated keys to dot notation in ConfigurationService
to prevent duplicate JSON entries. Add proactive normalization of
corrupted settings files in ConfigurationHelper. Extract shared
WriteSettingsFile/WriteSettingsFileAsync helpers.

Fixes #14795
Copilot AI review requested due to automatic review settings March 4, 2026 00:46
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14921

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14921"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash in aspire config when users mix colon (:) and dot (.) notation for the same logical configuration path by normalizing key handling and proactively repairing already-corrupted settings files before they’re loaded into IConfiguration.

Changes:

  • Normalize colon-separated keys to dot notation when setting, deleting, and listing configuration values to ensure a single nested JSON representation.
  • Add proactive settings-file normalization during settings registration to repair files containing both a nested object and a flat colon key for the same path.
  • Centralize settings JSON serialization/writes into ConfigurationHelper and add unit tests covering colon/dot scenarios and recovery.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/Aspire.Cli.Tests/Commands/ConfigCommandTests.cs Adds tests verifying colon-notation produces nested JSON, avoids duplicate-key states, supports delete, and repairs corrupted settings files.
src/Aspire.Cli/Utils/ConfigurationHelper.cs Introduces settings-file write helpers and adds proactive normalization of flat colon keys into nested objects before AddJsonFile.
src/Aspire.Cli/Configuration/ConfigurationService.cs Normalizes colon/dot usage in set/delete/flatten code paths and delegates settings file writes to ConfigurationHelper.

TryNormalizeSettingsFile now preserves existing nested values when a flat
colon key maps to a path that already exists. When both forms are present
the nested value wins and the flat key is dropped.

Added test asserting the chosen precedence behavior.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 4, 2026

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit 54414b6:

Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AgentInitCommand_WithMalformedMcpJson_ShowsErrorAndExitsNonZero ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateStartWaitAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording

📹 Recordings uploaded automatically from CI run #22650543423

@JamesNK JamesNK merged commit 89e9d60 into release/13.2 Mar 4, 2026
758 of 761 checks passed
@JamesNK JamesNK deleted the jamesnk/fix-duplicate-config-keys branch March 4, 2026 05:17
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants