{"record":{"id":"39872df6e302ab89","repo":"microsoft/aspire","slug":"no-items-available-for-selection-0","errorCode":null,"errorMessage":"No items available for selection: {0}","messagePattern":"No items available for selection: (.+?)","errorType":"exception","errorClass":"EmptyChoicesException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Interaction/ConsoleInteractionService.cs","lineNumber":319,"sourceCode":"        if (!_hostEnvironment.SupportsInteractiveInput)\n        {\n            if (binding != null)\n            {\n                if (binding.NonInteractiveDefaultValue != null)\n                {\n                    return MatchChoiceOrThrow(binding.NonInteractiveDefaultValue, binding, choicesList, choiceFormatter);\n                }\n\n                ThrowNonInteractiveError(binding.SymbolDisplayName);\n            }\n\n            throw new InvalidOperationException(InteractionServiceStrings.InteractiveInputNotSupported);\n        }\n\n        // Check if the choices collection is empty to avoid throwing an InvalidOperationException\n        if (choicesList.Count == 0)\n        {\n            throw new EmptyChoicesException(string.Format(CultureInfo.CurrentCulture, InteractionServiceStrings.NoItemsAvailableForSelection, promptText));\n        }\n\n        // Buffer console logs while interactive prompts are active so\n        // background debug output doesn't drown the prompt UI.\n        using var promptScope = _logBufferContext.BeginInteractivePromptScope();\n\n        MessageLogger.LogInformation(\"Selection prompt: {PromptText}\", promptText);\n\n        var prompt = new SelectionPrompt<T>()\n            .Title(promptText)\n            .UseConverter(choiceFormatter)\n            .AddChoices(choicesList)\n            .PageSize(10)\n            .EnableSearch();\n\n        prompt.SearchHighlightStyle = s_searchHighlightStyle;\n\n        var result = await MessageConsole.PromptAsync(prompt, cancellationToken);","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Interaction/ConsoleInteractionService.cs#L301-L337","documentation":"PromptForSelectionAsync validates the choices collection before showing the picker and throws EmptyChoicesException when it is empty, avoiding a less clear InvalidOperationException from the prompt library deeper down. The {0} placeholder is filled with the prompt text.","triggerScenarios":"Calling PromptForSelectionAsync with an empty choices list (or a collection whose deferred evaluation yields no items) regardless of interactivity.","commonSituations":"Enumerating available templates/channels/environments that returned zero results (e.g. network feed empty, no installed templates) and passing the empty result straight to the prompt; an upstream filter removing all candidates.","solutions":["Check the collection for elements before prompting and exit with a helpful message when empty.","Fix the data source so it actually returns choices (e.g. install templates, fix feed connectivity).","Guard the call with a non-empty assertion in tests.","Provide a default fallback choice when the source can legitimately be empty."],"exampleFix":"// before\nawait interaction.PromptForSelectionAsync(\"Pick a template\", templates, t => t.Name);\n// after\nif (templates.Count == 0)\n{\n    interaction.DisplayError(\"No templates available. Run 'dotnet new install' first.\");\n    return 1;\n}\nawait interaction.PromptForSelectionAsync(\"Pick a template\", templates, t => t.Name);","handlingStrategy":"validation","validationCode":"if (choices is null || choices.Count == 0)\n{\n    interaction.DisplayError(\"No options available to select.\");\n    return ExitCodeConstants.FailedToCreateNewProject;\n}","typeGuard":"bool hasChoices = choices is { Count: > 0 };","tryCatchPattern":"try { await interaction.PromptForSelectionAsync(prompt, choices, fmt); }\ncatch (EmptyChoicesException ex)\n{\n    interaction.DisplayError(ex.Message);\n    return ExitCodeConstants.FailedToCreateNewProject;\n}","preventionTips":["Check collection counts before prompting.","Log the upstream query that produced the choices to debug empty sources.","Add unit tests covering empty-source behavior.","Provide fallback defaults where emptiness is legitimate."],"tags":["cli","prompt","empty-collection","selection"],"backgroundTag":"empty-required-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}