{"record":{"id":"3b917806f244c8a3","repo":"netchx/netch","slug":"mode-not-found","errorCode":null,"errorMessage":"Mode not found.","messagePattern":"Mode not found\\.","errorType":"exception","errorClass":"MessageException","httpStatus":null,"severity":"warning","filePath":"Netch/Forms/MainForm.cs","lineNumber":947,"sourceCode":"\n        if (profile == null)\n        {\n            MessageBoxX.Show(i18N.Translate(\"No saved profile here. Save a profile first by Ctrl+Click on the button\"));\n            return;\n        }\n\n        try\n        {\n            ProfileNameText.Text = profile.ProfileName;\n\n            var server = ServerComboBox.Items.Cast<Server>().FirstOrDefault(s => s.Remark.Equals(profile.ServerRemark));\n            var mode = ModeComboBox.Items.Cast<Mode>().FirstOrDefault(m => m.Remark.Any(s => s.Value.Equals(profile.ModeRemark)));\n\n            if (server == null)\n                throw new MessageException(\"Server not found.\");\n\n            if (mode == null)\n                throw new MessageException(\"Mode not found.\");\n\n            // set active server and mode\n            ServerComboBox.SelectedItem = server;\n            ModeComboBox.SelectedItem = mode;\n        }\n        catch (MessageException exception)\n        {\n            MessageBoxX.Show(exception.Message, LogLevel.ERROR);\n            return;\n        }\n\n        await StopAsync();\n        ControlButton.PerformClick();\n    }\n\n    #endregion\n\n    #region State","sourceCodeStart":929,"sourceCodeEnd":965,"githubUrl":"https://github.com/netchx/netch/blob/9d99eb1c5a2acbf2a34f2600f94242601019a300/Netch/Forms/MainForm.cs#L929-L965","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-add or recreate the missing mode file under mode/ so one of its Remark dictionary values equals profile.ModeRemark.","Re-bind the profile: select a valid server and mode, then save the profile slot again to overwrite the stale ModeRemark.","Inspect the application log for 'Load mode \"<file>\" failed' entries, identify and fix the failing mode file.","Remove any DisableModeDirectoryFileName marker file inside a disabled mode directory to re-enable its modes."],"exampleFix":"// before\nvar mode = ModeComboBox.Items.Cast<Mode>().FirstOrDefault(m => m.Remark.Any(s => s.Value.Equals(profile.ModeRemark)));\nif (mode == null)\n    throw new MessageException(\"Mode not found.\");\n// after - fall back to the first available mode instead of throwing\nvar mode = ModeComboBox.Items.Cast<Mode>().FirstOrDefault(m => m.Remark.Any(s => s.Value.Equals(profile.ModeRemark)))\n           ?? ModeComboBox.Items.Cast<Mode>().FirstOrDefault();\nif (mode == null)\n{\n    MessageBoxX.Show(\"No mode available. Add a mode first.\", LogLevel.ERROR);\n    return;\n}","handlingStrategy":"validation","validationCode":"// Run before activating the profile\nvar modeExists = Global.Modes.Any(m => m.Remark.Values.Contains(profile.ModeRemark));\nif (!modeExists)\n{\n    Global.MainForm.NotifyTip($\"Profile '{profile.ProfileName}' references a missing mode.\");\n    return;\n}","typeGuard":"bool ModeRemarkExists(string remark) => Global.Modes.Any(m => m.Remark.Values.Contains(remark));","tryCatchPattern":"try { /* activate profile */ }\ncatch (MessageException ex) when (ex.Message == \"Mode not found.\")\n{\n    Log.Warning(\"Profile references missing mode; skipping activation\");\n}","preventionTips":["When renaming a mode, also update any profiles referencing its old remark.","Treat mode deletion as breaking for saved profiles; warn the user before deleting.","On startup, cross-check saved profiles against loaded modes and flag orphaned ones."],"tags":["profile","mode","lookup","combobox"],"backgroundTag":null,"analyzedSha":"9d99eb1c5a2acbf2a34f2600f94242601019a300","analyzedAt":"2026-08-13T14:12:19.105Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}