{"record":{"id":"0a906a0bb5e2c9d8","repo":"mRemoteNG/mRemoteNG","slug":"option-key-cannot-exceed-255-characters","errorCode":null,"errorMessage":"Option key cannot exceed 255 characters.","messagePattern":"Option key cannot exceed 255 characters\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"mRemoteNG/Config/Settings/OptionsRepository.cs","lineNumber":120,"sourceCode":"        }\n\n        #region Validation\n\n        private static void ValidateOption(OptionInfo option)\n        {\n            if (option == null)\n                throw new ArgumentNullException(nameof(option));\n\n            ValidateKey(option.Key);\n        }\n\n        private static void ValidateKey(string key)\n        {\n            if (string.IsNullOrWhiteSpace(key))\n                throw new ArgumentException(\"Option key cannot be null or whitespace.\", nameof(key));\n\n            if (key.Length > 255)\n                throw new ArgumentException(\"Option key cannot exceed 255 characters.\", nameof(key));\n        }\n\n        private static void ValidateCategory(string category)\n        {\n            if (string.IsNullOrWhiteSpace(category))\n                throw new ArgumentException(\"Category cannot be null or whitespace.\", nameof(category));\n\n            if (category.Length > 255)\n                throw new ArgumentException(\"Category cannot exceed 255 characters.\", nameof(category));\n        }\n\n        private static void ValidateId(int id)\n        {\n            if (id <= 0)\n                throw new ArgumentException(\"ID must be greater than 0.\", nameof(id));\n        }\n\n        #endregion","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/mRemoteNG/mRemoteNG/blob/9211babf35209d6171c8ff6e73bd856f11df21a5/mRemoteNG/Config/Settings/OptionsRepository.cs#L102-L138","documentation":"Thrown by OptionsRepository.ValidateKey when option.Key.Length > 255. The SQLite schema defines key as TEXT but the repository enforces a 255-character business cap (matching the index/key budget). Longer keys are rejected with ArgumentException.","triggerScenarios":"Calling any key-accepting method with a key longer than 255 characters — e.g. a generated GUID-heavy string, a base64 blob, or a path used as a key.","commonSituations":"Using a full file path, URL, or serialized object as the option key; concatenating identifiers without a length budget.","solutions":["Keep keys short identifiers (e.g. 'ui.theme', 'timeout.seconds'); store long data in Value, not Key.","Hash or truncate long identifiers before using them as a key (ensure uniqueness with a prefix/suffix).","Validate key.Length <= 255 in your input layer before calling the repository.","If you genuinely need long keys, raise the cap in ValidateKey and the schema."],"exampleFix":"// before\nawait repo.AddOptionAsync(new OptionInfo { Key = veryLongString });\n\n// after\nconst int MaxKey = 255;\nstring key = veryLongString.Length > MaxKey\n    ? veryLongString.Substring(0, MaxKey)\n    : veryLongString;\nawait repo.AddOptionAsync(new OptionInfo { Key = key });","handlingStrategy":"validation","validationCode":"const int MaxKey = 255;\nif (option.Key.Length > MaxKey)\n    throw new ArgumentException($\"Option key exceeds {MaxKey} characters.\");","typeGuard":"static bool IsKeyWithinLimit(string key) => key != null && key.Length <= 255;","tryCatchPattern":"try { await repo.AddOptionAsync(option); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"255\"))\n{ option.Key = option.Key.Substring(0, 255); await repo.AddOptionAsync(option); }","preventionTips":["Use short identifier-style keys; store long data in Value.","Validate key.Length <= 255 at the input boundary.","Hash long identifiers if you must derive a key from them.","Enforce the limit in form validators before submit."],"tags":["options","validation","length-limit","mremoteng"],"backgroundTag":null,"analyzedSha":"9211babf35209d6171c8ff6e73bd856f11df21a5","analyzedAt":"2026-08-13T19:31:27.817Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}