{"record":{"id":"a69a5d4bba05831e","repo":"mRemoteNG/mRemoteNG","slug":"negative-value-not-allowed-for-type-parameter","errorCode":null,"errorMessage":"Negative value not allowed for {type} parameter.","messagePattern":"Negative value not allowed for (.+?) parameter\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"mRemoteNG/Tools/WindowsRegistry/WinRegistryEntry.cs","lineNumber":735,"sourceCode":"\n        /// <summary>\n        /// Private method to validate the range values.\n        /// </summary>\n        /// <typeparam name=\"U\">The type of the values being validated.</typeparam>\n        /// <param name=\"minValue\">The minimum value of the range.</param>\n        /// <param name=\"maxValue\">The maximum value of the range.</param>\n        /// <param name=\"type\">The type of registry entry (used for error messages).</param>\n        private static void ValidateRange<U>(U minValue, U maxValue) where U : IComparable<U>\n        {\n            Type typeCode = typeof(U);\n\n            string type =\n                typeCode == typeof(int) ? \"dword\" :\n                typeCode == typeof(long) ? \"qword\"\n                : throw new ArgumentException(\"Registry entry type must be either Int32 or Int64 to use this validation.\");\n\n            if (minValue.CompareTo(default(U)) < 0)\n                throw new ArgumentException($\"Negative value not allowed for {type} parameter.\", nameof(minValue));\n            if (maxValue.CompareTo(default(U)) < 0)\n                throw new ArgumentException($\"Negative value not allowed for {type} parameter.\", nameof(maxValue));\n            if (minValue.CompareTo(maxValue) > 0)\n                throw new ArgumentException(\"MinValue must be less than or equal to MaxValue.\");\n        }\n\n        /// <summary>\n        /// Validates the specified registry value kind.\n        /// </summary>\n        /// <param name=\"valueKind\">The registry value kind to validate.</param>\n        /// <returns>The validated <see cref=\"RegistryValueKind\"/>.</returns>\n        /// <exception cref=\"ArgumentException\">Thrown when Invalid parameter: Unknown or unsupported <typeparamref name=\"valueKind\" value.</exception>\n        /// <exception cref=\"ArgumentException\">Thrown when Value type <typeparamref name=\"T\"/> is not supported.</exception>\n        private bool ValueKindValidationRule(RegistryValueKind valueKind)\n        {\n            if (!Enum.IsDefined(typeof(RegistryValueKind), valueKind) || valueKind == RegistryValueKind.Unknown || valueKind == RegistryValueKind.None || valueKind == 0)\n                throw new ArgumentException(\"Invalid parameter: Unknown or unsupported RegistryValueKind value.\", nameof(valueKind));\n","sourceCodeStart":717,"sourceCodeEnd":753,"githubUrl":"https://github.com/mRemoteNG/mRemoteNG/blob/9211babf35209d6171c8ff6e73bd856f11df21a5/mRemoteNG/Tools/WindowsRegistry/WinRegistryEntry.cs#L717-L753","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nentry.SetValidation(-5, 100);\n// after\nentry.SetValidation(0, 100);\n// or via the string overload\nentry.SetValidation(\"*\", \"100\");","handlingStrategy":"validation","validationCode":"int min = ComputeMin();\nif (min < 0) throw new ArgumentOutOfRangeException(nameof(min), \"min must be non-negative for this registry entry.\");\nentry.SetValidation(min, max);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["windows-registry","validation","range","negative-value"],"backgroundTag":null,"analyzedSha":"9211babf35209d6171c8ff6e73bd856f11df21a5","analyzedAt":"2026-08-13T19:31:27.817Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}