{"record":{"id":"2790dcdf302538ad","repo":"JamesNK/Newtonsoft.Json","slug":"value","errorCode":null,"errorMessage":"value","messagePattern":"value","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs","lineNumber":61,"sourceCode":"        {\n            _lineInfoHandling = LineInfoHandling.Load;\n            _commentHandling = CommentHandling.Ignore;\n            _duplicatePropertyNameHandling = DuplicatePropertyNameHandling.Replace;\n        }\n\n        /// <summary>\n        /// Gets or sets how JSON comments are handled when loading JSON.\n        /// The default value is <see cref=\"CommentHandling.Ignore\" />.\n        /// </summary>\n        /// <value>The JSON comment handling.</value>\n        public CommentHandling CommentHandling\n        {\n            get => _commentHandling;\n            set\n            {\n                if (value < CommentHandling.Ignore || value > CommentHandling.Load)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(value));\n                }\n\n                _commentHandling = value;\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets how JSON line info is handled when loading JSON.\n        /// The default value is <see cref=\"LineInfoHandling.Load\" />.\n        /// </summary>\n        /// <value>The JSON line info handling.</value>\n        public LineInfoHandling LineInfoHandling\n        {\n            get => _lineInfoHandling;\n            set\n            {\n                if (value < LineInfoHandling.Ignore || value > LineInfoHandling.Load)\n                {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JsonLoadSettings.cs#L43-L79","documentation":"ArgumentOutOfRangeException(nameof(value)) from the CommentHandling property setter on JsonLoadSettings. The setter validates that the assigned enum is within the declared range (CommentHandling.Ignore..CommentHandling.Load); an out-of-range value (typically an uninitialised/cast integer) is rejected. nameof(value) is the formal parameter name, which is why the message is just \"value\".","triggerScenarios":"Assigning settings.CommentHandling = (CommentHandling)999; or casting an arbitrary int to CommentHandling. Also when a config-binding system binds a numeric value that does not map to a defined enum member.","commonSituations":"Configuration-driven JsonLoadSettings where an invalid enum string/number is bound; reflection-based assignment of unknown enum ints; deserializing the settings object from JSON with an invalid enum value.","solutions":["Validate the enum with Enum.IsDefined before assigning: if (Enum.IsDefined(typeof(CommentHandling), v)) settings.CommentHandling = v;","Bind configuration using enum-aware binding that rejects unknown values upstream.","Default-initialise JsonLoadSettings and only override validated values."],"exampleFix":"// before\nsettings.CommentHandling = (CommentHandling)configValue;\n\n// after\nif (Enum.IsDefined(typeof(CommentHandling), configValue))\n    settings.CommentHandling = (CommentHandling)configValue;","handlingStrategy":"validation","validationCode":"if (Enum.IsDefined(typeof(CommentHandling), v)) settings.CommentHandling = (CommentHandling)v;","typeGuard":"static bool IsValidCommentHandling(int v) => Enum.IsDefined(typeof(CommentHandling), v);","tryCatchPattern":"try { settings.CommentHandling = (CommentHandling)configValue; } catch (ArgumentOutOfRangeException) { /* keep default */ }","preventionTips":["Validate enum values with Enum.IsDefined before assigning.","Use enum-aware configuration binding.","Default-initialise JsonLoadSettings and override only validated values."],"tags":["jsonloadsettings","argumentoutofrange","enum","validation","configuration"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}