{"record":{"id":"2a54cddfc589bbaf","repo":"JamesNK/Newtonsoft.Json","slug":"value-must-be-positive-2a54cd","errorCode":null,"errorMessage":"Value must be positive.","messagePattern":"Value must be positive\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/JsonSerializer.cs","lineNumber":528,"sourceCode":"        public virtual CultureInfo Culture\n        {\n            get => _culture ?? JsonSerializerSettings.DefaultCulture;\n            set => _culture = value;\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 virtual int? MaxDepth\n        {\n            get => _maxDepth;\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        /// Gets a value indicating whether there will be a check for additional JSON content after deserializing an object.\n        /// The default value is <c>false</c>.\n        /// </summary>\n        /// <value>\n        /// \t<c>true</c> if there will be a check for additional JSON content after deserializing an object; otherwise, <c>false</c>.\n        /// </value>\n        public virtual bool CheckAdditionalContent\n        {\n            get => _checkAdditionalContent ?? JsonSerializerSettings.DefaultCheckAdditionalContent;\n            set => _checkAdditionalContent = value;","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonSerializer.cs#L510-L546","documentation":"Thrown by the JsonSerializer.MaxDepth setter when assigning a value less than or equal to zero. MaxDepth bounds JSON nesting depth to prevent stack overflows and denial-of-service via pathological/deeply-nested input; a non-positive bound is invalid, so the setter rejects it with ArgumentException. Null means no limit and is allowed.","triggerScenarios":"Setting serializer.MaxDepth = 0 or a negative number; feeding MaxDepth from unvalidated config or arithmetic that can go non-positive.","commonSituations":"Reading MaxDepth from appsettings/environment without bounds checking; passing 0 intending 'default'; subtractive arithmetic producing negatives.","solutions":["Assign a positive integer (64 is the library default).","Pass null to explicitly disable the cap.","Validate first: if (depth is int d && d > 0) serializer.MaxDepth = d;."],"exampleFix":"// before\nserializer.MaxDepth = 0;\n\n// after\nserializer.MaxDepth = 64; // or null for no limit","handlingStrategy":"validation","validationCode":"if (configuredDepth is int d && d > 0)\n{\n    serializer.MaxDepth = d;\n}","typeGuard":"static bool IsValidMaxDepth(int? v) => v is null or > 0;","tryCatchPattern":null,"preventionTips":["Use 64 (default) or another positive value; use null for no cap.","Validate config at load time and fail loudly.","Do not derive MaxDepth from untrusted arithmetic without clamping."],"tags":["configuration","validation","max-depth"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}