netchx/netch · warning · MessageException

Mode not found.

Error message

Mode not found.

What it means

Thrown while activating a saved profile whose stored ModeRemark no longer matches any Mode loaded into the ModeComboBox. Netch profiles persist only the mode's remark string (profile.ModeRemark); the handler does a FirstOrDefault over ModeComboBox items matching any value of the mode's Remark dictionary. If no mode matches (file deleted/renamed/disabled/failed to load), the lookup is null and this MessageException fires. It is caught immediately in the same try/catch, shown via MessageBoxX(LogLevel.ERROR), and the handler returns without starting the server.

Source

Thrown at Netch/Forms/MainForm.cs:947

        if (profile == null)
        {
            MessageBoxX.Show(i18N.Translate("No saved profile here. Save a profile first by Ctrl+Click on the button"));
            return;
        }

        try
        {
            ProfileNameText.Text = profile.ProfileName;

            var server = ServerComboBox.Items.Cast<Server>().FirstOrDefault(s => s.Remark.Equals(profile.ServerRemark));
            var mode = ModeComboBox.Items.Cast<Mode>().FirstOrDefault(m => m.Remark.Any(s => s.Value.Equals(profile.ModeRemark)));

            if (server == null)
                throw new MessageException("Server not found.");

            if (mode == null)
                throw new MessageException("Mode not found.");

            // set active server and mode
            ServerComboBox.SelectedItem = server;
            ModeComboBox.SelectedItem = mode;
        }
        catch (MessageException exception)
        {
            MessageBoxX.Show(exception.Message, LogLevel.ERROR);
            return;
        }

        await StopAsync();
        ControlButton.PerformClick();
    }

    #endregion

    #region State

View on GitHub (pinned to 9d99eb1c5a)

Solutions

  1. Re-add or recreate the missing mode file under mode/ so one of its Remark dictionary values equals profile.ModeRemark.
  2. Re-bind the profile: select a valid server and mode, then save the profile slot again to overwrite the stale ModeRemark.
  3. Inspect the application log for 'Load mode "<file>" failed' entries, identify and fix the failing mode file.
  4. Remove any DisableModeDirectoryFileName marker file inside a disabled mode directory to re-enable its modes.

Example fix

// before
var mode = ModeComboBox.Items.Cast<Mode>().FirstOrDefault(m => m.Remark.Any(s => s.Value.Equals(profile.ModeRemark)));
if (mode == null)
    throw new MessageException("Mode not found.");
// after - fall back to the first available mode instead of throwing
var mode = ModeComboBox.Items.Cast<Mode>().FirstOrDefault(m => m.Remark.Any(s => s.Value.Equals(profile.ModeRemark)))
           ?? ModeComboBox.Items.Cast<Mode>().FirstOrDefault();
if (mode == null)
{
    MessageBoxX.Show("No mode available. Add a mode first.", LogLevel.ERROR);
    return;
}
Defensive patterns

Strategy: validation

Validate before calling

// Run before activating the profile
var modeExists = Global.Modes.Any(m => m.Remark.Values.Contains(profile.ModeRemark));
if (!modeExists)
{
    Global.MainForm.NotifyTip($"Profile '{profile.ProfileName}' references a missing mode.");
    return;
}

Type guard

bool ModeRemarkExists(string remark) => Global.Modes.Any(m => m.Remark.Values.Contains(remark));

Try / catch

try { /* activate profile */ }
catch (MessageException ex) when (ex.Message == "Mode not found.")
{
    Log.Warning("Profile references missing mode; skipping activation");
}

Prevention

When it happens

Trigger: Ctrl-clicking/activating a profile slot after its mode file was removed from the mode/ tree, after the mode's remark was edited, or after its mode directory was disabled via a DisableModeDirectoryFileName marker. Because the match is exact against m.Remark dictionary values, even a remark re-translation breaks the lookup.

Common situations: Mode file deleted or moved; mode remark edited after the profile was saved; mode directory disabled; a mode file failed to load (see ModeService.LoadCore 'Load mode ... failed' warnings) so the expected Mode is absent; profile migrated across Netch versions whose default mode remarks differ.

Related errors


AI-assisted analysis of netchx/netch@9d99eb1c5a (2026-08-13). Data as JSON: /api/errors/3b917806f244c8a3. Report an issue: GitHub.