mRemoteNG/mRemoteNG · error · ArgumentException
Option key cannot exceed 255 characters.
Error message
Option key cannot exceed 255 characters.
What it means
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.
Source
Thrown at mRemoteNG/Config/Settings/OptionsRepository.cs:120
}
#region Validation
private static void ValidateOption(OptionInfo option)
{
if (option == null)
throw new ArgumentNullException(nameof(option));
ValidateKey(option.Key);
}
private static void ValidateKey(string key)
{
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentException("Option key cannot be null or whitespace.", nameof(key));
if (key.Length > 255)
throw new ArgumentException("Option key cannot exceed 255 characters.", nameof(key));
}
private static void ValidateCategory(string category)
{
if (string.IsNullOrWhiteSpace(category))
throw new ArgumentException("Category cannot be null or whitespace.", nameof(category));
if (category.Length > 255)
throw new ArgumentException("Category cannot exceed 255 characters.", nameof(category));
}
private static void ValidateId(int id)
{
if (id <= 0)
throw new ArgumentException("ID must be greater than 0.", nameof(id));
}
#endregionView on GitHub (pinned to 9211babf35)
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.
Example fix
// before
await repo.AddOptionAsync(new OptionInfo { Key = veryLongString });
// after
const int MaxKey = 255;
string key = veryLongString.Length > MaxKey
? veryLongString.Substring(0, MaxKey)
: veryLongString;
await repo.AddOptionAsync(new OptionInfo { Key = key }); Defensive patterns
Strategy: validation
Validate before calling
const int MaxKey = 255;
if (option.Key.Length > MaxKey)
throw new ArgumentException($"Option key exceeds {MaxKey} characters."); Type guard
static bool IsKeyWithinLimit(string key) => key != null && key.Length <= 255;
Try / catch
try { await repo.AddOptionAsync(option); }
catch (ArgumentException ex) when (ex.Message.Contains("255"))
{ option.Key = option.Key.Substring(0, 255); await repo.AddOptionAsync(option); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Using a full file path, URL, or serialized object as the option key; concatenating identifiers without a length budget.
Related errors
- Category cannot exceed 255 characters.
- An option with key '{option.Key}' already exists.
- Option key cannot be null or whitespace.
- Category cannot be null or whitespace.
- ID must be greater than 0.
AI-assisted analysis of mRemoteNG/mRemoteNG@9211babf35 (2026-08-13).
Data as JSON: /api/errors/0a906a0bb5e2c9d8.
Report an issue: GitHub.