{"record":{"id":"d2e5da19f6d7f3aa","repo":"JamesNK/Newtonsoft.Json","slug":"value-must-be-positive-d2e5da","errorCode":null,"errorMessage":"Value must be positive.","messagePattern":"Value must be positive\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/JsonSerializerSettings.cs","lineNumber":344,"sourceCode":"            {\n                _dateFormatString = value;\n                _dateFormatStringSet = true;\n            }\n        }\n\n        /// <summary>\n        /// Gets or sets the maximum depth allowed when reading JSON. Reading past this depth will throw a <see cref=\"JsonReaderException\"/>.\n        /// A null value means there is no maximum.\n        /// The default value is <c>64</c>.\n        /// </summary>\n        public int? MaxDepth\n        {\n            get => _maxDepthSet ? _maxDepth : DefaultMaxDepth;\n            set\n            {\n                if (value <= 0)\n                {\n                    throw new ArgumentException(\"Value must be positive.\", nameof(value));\n                }\n\n                _maxDepth = value;\n                _maxDepthSet = true;\n            }\n        }\n\n        /// <summary>\n        /// Indicates how JSON text output is formatted.\n        /// The default value is <see cref=\"Json.Formatting.None\" />.\n        /// </summary>\n        public Formatting Formatting\n        {\n            get => _formatting ?? DefaultFormatting;\n            set => _formatting = value;\n        }\n\n        /// <summary>","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonSerializerSettings.cs#L326-L362","documentation":"Thrown by the JsonSerializerSettings.MaxDepth setter when assigning a value less than or equal to zero. Like the reader/serializer MaxDepth, it bounds nesting depth for safety against deep/malicious JSON; non-positive values are invalid and rejected with ArgumentException. Null disables the limit.","triggerScenarios":"Setting settings.MaxDepth = 0 or negative; sourcing MaxDepth from config/env/user input without validation; arithmetic that yields a non-positive value.","commonSituations":"Appsettings/environment values parsed to 0; passing 0 intending default; conditional logic that subtracts depth.","solutions":["Use a positive integer (default is 64).","Pass null to disable the cap explicitly.","Validate config before assignment: settings.MaxDepth = (depth > 0) ? depth : null;."],"exampleFix":"// before\nsettings.MaxDepth = 0;\n\n// after\nsettings.MaxDepth = 64; // or null","handlingStrategy":"validation","validationCode":"settings.MaxDepth = configuredDepth switch\n{\n    int d when d > 0 => d,\n    _ => (int?)null,\n};","typeGuard":"static bool IsValidMaxDepth(int? v) => v is null or > 0;","tryCatchPattern":null,"preventionTips":["Validate config-driven MaxDepth at load time.","Treat null as no-limit, never 0.","Clamp parsed values into a sane positive range."],"tags":["configuration","validation","max-depth"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}