Fix duplicate keys in aspire config set with colon notation#14921
Merged
JamesNK merged 2 commits intorelease/13.2from Mar 4, 2026
Merged
Fix duplicate keys in aspire config set with colon notation#14921JamesNK merged 2 commits intorelease/13.2from
JamesNK merged 2 commits intorelease/13.2from
Conversation
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
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14921Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 14921" |
Contributor
There was a problem hiding this comment.
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
ConfigurationHelperand 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.
Contributor
🎬 CLI E2E Test RecordingsThe following terminal recordings are available for commit
📹 Recordings uploaded automatically from CI run #22650543423 |
adamint
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix duplicate key errors in
aspire configcommands when users mix colon (:) and dot (.) notation for the same configuration key.Problem: Running
aspire config set features:polyglotSupportEnabled truefollowed byaspire config set features.polyglotSupportEnabled truecreates 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 throwsFormatException: A duplicate key was found, crashing the CLI.Fix:
SetNestedValue,DeleteNestedValue, andFlattenJsonObjectso both separators produce the same nested JSON.ConfigurationHelper.RegisterSettingsFiles.WriteSettingsFile/WriteSettingsFileAsynchelpers toConfigurationHelperto centralize settings file serialization.Fixes #14795
Checklist