Skip to content

CmdPal crash: During a search, List<T>(capacity) in MainListPage.UpdateSearchTextCore received a negative capacity. #46210

@Aalivexy

Description

@Aalivexy

Microsoft PowerToys version

0.98.0

Installation method

Microsoft Store

Area(s) with issue?

Command Palette

Steps to reproduce

Disable most extensions, leaving only one or two commands.

✔️ Expected Behavior

Display the results returned by the extension.

❌ Actual Behavior

Error(s) on page:
============================================================
😢 An unexpected error occurred in the application.

Summary:
  Message:    Non-negative number required. (Parameter 'capacity')
  Type:       System.ArgumentOutOfRangeException
  Source:     <unknown>
  Time:       2026-03-18 15:29:00.4763082
  HRESULT:    0x80131502 (-2146233086)

Stack Trace:
   at System.Collections.Generic.List`1..ctor(Int32) + 0x66
   at Microsoft.CmdPal.UI.ViewModels.MainPage.MainListPage.UpdateSearchTextCore(String, String, Boolean) + 0x3e5
   at Microsoft.CmdPal.UI.ViewModels.ListViewModel.<>c__DisplayClass71_0.<OnSearchTextBoxUpdated>b__0() + 0x71

------------------ Full Exception Details ------------------
System.ArgumentOutOfRangeException: Non-negative number required. (Parameter 'capacity')
   at System.Collections.Generic.List`1..ctor(Int32) + 0x66
   at Microsoft.CmdPal.UI.ViewModels.MainPage.MainListPage.UpdateSearchTextCore(String, String, Boolean) + 0x3e5
   at Microsoft.CmdPal.UI.ViewModels.ListViewModel.<>c__DisplayClass71_0.<OnSearchTextBoxUpdated>b__0() + 0x71

ℹ️ If you need further assistance, please include this information in your support request.
ℹ️ Before sending, take a quick look to make sure it doesn't contain any personal or sensitive information.
============================================================

Additional Information

It appears that in ProviderSettings, the values of FallbackCommands with IncludeInGlobalResults set to true are still being counted toward the global fallback total even for providers that have been disabled. This causes the global fallback count to exceed the actual number of commands, which in turn makes the capacity negative in the code below and leads to a crash:

var commonFallbacks = new List<TopLevelViewModel>(commands.Count - globalFallbacks.Length);

Perhaps we should filter out disabled items when calculating globalFallbacks.

public string[] GetGlobalFallbacks()
{
var globalFallbacks = new HashSet<string>();
foreach (var provider in ProviderSettings.Values)
{
foreach (var fallback in provider.FallbackCommands)
{
var fallbackSetting = fallback.Value;
if (fallbackSetting.IsEnabled && fallbackSetting.IncludeInGlobalResults)
{
globalFallbacks.Add(fallback.Key);
}
}
}
return globalFallbacks.ToArray();
}

Metadata

Metadata

Assignees

Labels

0.98.1Issue-BugSomething isn't workingNeeds-TriageFor issues raised to be triaged and prioritized by internal Microsoft teamsProduct-Command PaletteRefers to the Command Palette utilityStatus-In progressThis issue or work-item is under development

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions