netchx/netch · warning · MessageException

Server not found.

Error message

Server not found.

What it means

Thrown by MainForm profile activation when no Server in ServerComboBox has a Remark equal to profile.ServerRemark — i.e. the saved profile references a server that no longer exists (deleted or renamed). The first FirstOrDefault returns null and the guard fires before the mode lookup. It is caught immediately and shown via MessageBoxX (LogLevel.ERROR), so it is a user-facing warning rather than a crash.

Source

Thrown at Netch/Forms/MainForm.cs:944

        }

        // Activate Profile

        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();
    }

View on GitHub (pinned to 9d99eb1c5a)

Solutions

  1. Re-create or rename a server so its Remark matches profile.ServerRemark.
  2. Edit the profile to point at an existing server (re-save it via Ctrl+Click).
  3. Delete the stale profile if the server is gone for good.
  4. Keep server Remarks stable, or update profiles immediately after renaming a server.
Defensive patterns

Strategy: validation

Validate before calling

// Before activating a profile, confirm its referenced server still exists.
var exists = ServerComboBox.Items.Cast<Server>().Any(s => s.Remark.Equals(profile.ServerRemark));
if (!exists)
{
    MessageBoxX.Show($"Profile '{profile.ProfileName}' references a server that no longer exists.", LogLevel.ERROR);
    return;
}

Try / catch

try { /* profile activation block */ }
catch (MessageException ex) when (ex.Message == "Server not found." || ex.Message == "Mode not found.")
{
    // already shown via the surrounding catch(MessageException) -> MessageBoxX; offer to delete the stale profile.
    OfferDeleteStaleProfile(profile);
}

Prevention

When it happens

Trigger: A profile was saved against a server that has since been deleted; the server's Remark was edited after the profile was created; profile import from another machine whose server list differs; empty/migrated server list with old profiles.

Common situations: User deleted a server but kept profiles that point at it; renamed a server; copied profiles.xml between machines without copying servers; data drift after a config migration.

Related errors


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