Skip to content

![high](https://www.gstatic.com/codereviewagent/high-priority.svg) #3

@Jakobish

Description

@Jakobish

high

When setting the configuration for a side, if the CurrentMode is Site and the $Config.Value (the site name) does not exist in the target SiteCombo's items, the script attempts to set the Text property of the combobox. Since this combobox has its DropDownStyle set to DropDownList, this will cause an exception. This can happen when copying or swapping between sides that have different lists of IIS sites.

The correct behavior would be to handle this case gracefully, for example by clearing the selection when the site is not found.

    if ($state.CurrentMode -eq "Site") {
        if ($Config.Value) {
            $index = $state.SiteCombo.Items.IndexOf($Config.Value)
            if ($index -ge 0) {
                $state.SiteCombo.SelectedIndex = $index
            }
            else {
                # Site from source/other side doesn't exist here, so clear selection.
                $state.SiteCombo.SelectedIndex = -1
            }
        }
        else {
            $state.SiteCombo.SelectedIndex = -1
        }
    }

Originally posted by @gemini-code-assist[bot] in #1 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions