mRemoteNG/mRemoteNG · error · ArgumentException
Negative value not allowed for {type} parameter.
Error message
Negative value not allowed for {type} parameter. What it means
Thrown by ValidateRange when minValue is less than default(U) (i.e. negative), reached via SetValidation(int,int), SetValidation(long,long), or the string overload that delegates to them. The library constrains dword/qword registry ranges to non-negative values because it later defaults the missing bound to 0 and stores them in int?/long? fields used for clamping.
Source
Thrown at mRemoteNG/Tools/WindowsRegistry/WinRegistryEntry.cs:735
/// <summary>
/// Private method to validate the range values.
/// </summary>
/// <typeparam name="U">The type of the values being validated.</typeparam>
/// <param name="minValue">The minimum value of the range.</param>
/// <param name="maxValue">The maximum value of the range.</param>
/// <param name="type">The type of registry entry (used for error messages).</param>
private static void ValidateRange<U>(U minValue, U maxValue) where U : IComparable<U>
{
Type typeCode = typeof(U);
string type =
typeCode == typeof(int) ? "dword" :
typeCode == typeof(long) ? "qword"
: throw new ArgumentException("Registry entry type must be either Int32 or Int64 to use this validation.");
if (minValue.CompareTo(default(U)) < 0)
throw new ArgumentException($"Negative value not allowed for {type} parameter.", nameof(minValue));
if (maxValue.CompareTo(default(U)) < 0)
throw new ArgumentException($"Negative value not allowed for {type} parameter.", nameof(maxValue));
if (minValue.CompareTo(maxValue) > 0)
throw new ArgumentException("MinValue must be less than or equal to MaxValue.");
}
/// <summary>
/// Validates the specified registry value kind.
/// </summary>
/// <param name="valueKind">The registry value kind to validate.</param>
/// <returns>The validated <see cref="RegistryValueKind"/>.</returns>
/// <exception cref="ArgumentException">Thrown when Invalid parameter: Unknown or unsupported <typeparamref name="valueKind" value.</exception>
/// <exception cref="ArgumentException">Thrown when Value type <typeparamref name="T"/> is not supported.</exception>
private bool ValueKindValidationRule(RegistryValueKind valueKind)
{
if (!Enum.IsDefined(typeof(RegistryValueKind), valueKind) || valueKind == RegistryValueKind.Unknown || valueKind == RegistryValueKind.None || valueKind == 0)
throw new ArgumentException("Invalid parameter: Unknown or unsupported RegistryValueKind value.", nameof(valueKind));
View on GitHub (pinned to 9211babf35)
Solutions
- Pass a non-negative minValue (>= 0).
- Use the string overload with null/empty or "*" for minValue to let it default to 0 (see lines 373-374).
- If negative semantics are required, this library does not support them; clamp and validate at the application layer instead.
Example fix
// before
entry.SetValidation(-5, 100);
// after
entry.SetValidation(0, 100);
// or via the string overload
entry.SetValidation("*", "100"); Defensive patterns
Strategy: validation
Validate before calling
int min = ComputeMin(); if (min < 0) throw new ArgumentOutOfRangeException(nameof(min), "min must be non-negative for this registry entry."); entry.SetValidation(min, max);
Prevention
- Sanitize lower bounds to 0 before calling SetValidation.
- Use the string overload with "*" for the minimum to default it to 0.
- Remember dword/qword ranges in this library are non-negative only.
When it happens
Trigger: Calling SetValidation(-5, 100) on a WinRegistryEntry<int>, SetValidation(-1L, 100L) on a WinRegistryEntry<long>, or SetValidation("-5","100") which parses to a negative minIntValue/minLongValue.
Common situations: Developer assumes int/long ranges accept negatives and passes a negative lower bound to clamp a registry setting that this library treats as unsigned (0..MaxValue).
Related errors
- MinValue must be less than or equal to MaxValue.
- Invalid minimum value for Int32.
- Invalid maximum value for Int32.
- Invalid minimum value for Int64.
- Invalid maximum value for Int64.
AI-assisted analysis of mRemoteNG/mRemoteNG@9211babf35 (2026-08-13).
Data as JSON: /api/errors/a69a5d4bba05831e.
Report an issue: GitHub.