Fix crash when multiple plugins register the same command#1691
Merged
waldekmastykarz merged 2 commits intoJun 4, 2026
Merged
Conversation
When using EntraMockResponsePlugin and MockResponsePlugin together, or multiple instances of MockResponsePlugin, the proxy crashes with ArgumentException due to duplicate 'mocks' command registration. Deduplicate plugin commands by name (matching the existing approach for options) and log a warning when duplicates are found. Closes dotnet#1690 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a startup crash in Dev Proxy’s CLI when multiple loaded plugins register a command with the same name (e.g., "mocks" from both EntraMockResponsePlugin and MockResponsePlugin). It updates the root DevProxyCommand command registration flow to deduplicate plugin commands by name, preventing System.CommandLine from throwing during tokenization/parsing.
Changes:
- Collect plugin-provided commands and group them by
Command.Namebefore registration. - Register only the first command per name and log a warning when duplicates are detected.
garrytrinder
approved these changes
Jun 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.
Summary
Fixes the
ArgumentException: An item with the same key has already been added. Key: mockscrash when usingEntraMockResponsePluginandMockResponsePlugintogether, or multiple instances ofMockResponsePlugin.Root cause
EntraMockResponsePlugininherits fromMockResponsePlugin, which registers a"mocks"command viaGetCommands(). When both plugins are loaded, two"mocks"commands are registered, causingSystem.CommandLineto throw. The same crash occurs with twoMockResponsePlugininstances using different config sections.This is a regression introduced in v1.1.0 when
GetCommands()was added toMockResponsePlugin(PR #1262).Fix
Deduplicate plugin commands by name before registering them — matching the existing approach for options (line 589-593). When duplicates are found, the first registration wins and a warning is logged so users and plugin authors aren't left guessing.
Closes #1690