From 5572bdcca13bc47cfbcbc8e7bac5185c037c51d3 Mon Sep 17 00:00:00 2001 From: Waldek Mastykarz Date: Thu, 4 Jun 2026 15:18:20 +0200 Subject: [PATCH] Fix crash when multiple plugins register the same command 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/dev-proxy#1690 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- DevProxy/Commands/DevProxyCommand.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/DevProxy/Commands/DevProxyCommand.cs b/DevProxy/Commands/DevProxyCommand.cs index 2ff5502b..4308bc65 100644 --- a/DevProxy/Commands/DevProxyCommand.cs +++ b/DevProxy/Commands/DevProxyCommand.cs @@ -606,7 +606,18 @@ private void ConfigureCommand() ActivatorUtilities.CreateInstance(_serviceProvider), ActivatorUtilities.CreateInstance(_serviceProvider) }; - commands.AddRange(_plugins.SelectMany(p => p.GetCommands())); + var pluginCommands = _plugins.SelectMany(p => p.GetCommands()); + foreach (var group in pluginCommands.GroupBy(c => c.Name)) + { + var command = group.First(); + commands.Add(command); + if (group.Count() > 1) + { + _logger.LogWarning( + "Multiple plugins register the '{CommandName}' command. Only the first registration will be used", + command.Name); + } + } this.AddCommands(commands.OrderByName()); HelpExamples.Add(this, [