{"record":{"id":"435e86038a0bccd7","repo":"JamesNK/Newtonsoft.Json","slug":"parametername","errorCode":null,"errorMessage":"{parameterName}","messagePattern":"\\{parameterName\\}","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Utilities/ValidationUtils.cs","lineNumber":38,"sourceCode":"// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n// OTHER DEALINGS IN THE SOFTWARE.\n#endregion\n\nusing System;\nusing System.Diagnostics.CodeAnalysis;\nusing System.Runtime.CompilerServices;\n\nnamespace Newtonsoft.Json.Utilities\n{\n    internal static class ValidationUtils\n    {\n        public static void ArgumentNotNull([NotNull]object? value, string parameterName)\n        {\n            if (value == null)\n            {\n                throw new ArgumentNullException(parameterName);\n            }\n        }\n    }\n}","sourceCodeStart":20,"sourceCodeEnd":42,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Utilities/ValidationUtils.cs#L20-L42","documentation":"The central null-argument guard used across the entire Newtonsoft.Json API surface (Src/Newtonsoft.Json/Utilities/ValidationUtils.cs:34-40). ValidationUtils.ArgumentNotNull(value, parameterName) throws an ArgumentNullException whose ParamName and message equal the supplied parameterName whenever value is null. Dozens of public entry points funnel through it - JsonConvert.DeserializeObject (JsonConvert.cs:857), JsonSerializer.Serialize/Deserialize with null readers/writers/targets (JsonSerializer.cs:811,890,1091,1204), JsonWriter.WriteFromReader (JsonWriter.cs:511+), converters (StringEnumConverter.cs:134), contract resolvers, reflection value providers, and formatter converters - so this is the library's standard 'you passed null where a non-null argument is required' signal. The thrown message is literally the parameter name (e.g. 'value', 'reader', 'type'), which tells you exactly which argument was null.","triggerScenarios":"Passing null to any guarded public API: JsonConvert.DeserializeObject(null, ...), JsonSerializer.Deserialize with a null JsonReader, JsonSerializer.Serialize with a null JsonWriter, a null Type/objectType to DefaultContractResolver.ResolveContract or JsonContract, null value/reader/writer in converter and formatter code (FormatterConverter.cs, JsonFormatterConverter.cs), null memberInfo to value providers, null creator in JsonSerializerInternalReader, etc. The ArgumentNullException.ParamName identifies the offending argument.","commonSituations":"Deserializing from a JSON string that came back null from an HTTP response, config file, or DB read; passing a null TextReader/JsonReader; nullable reference types disabled so the compiler never warned; a refactor that introduced null where a non-null overload was expected; null JsonSerializerSettings.TypeNameHandling-related type arguments.","solutions":["Null-check the argument before calling and handle the absent value (return early, use a default, or log): if (jsonString is null) return null;","Switch to an overload that tolerates null for that argument where one exists (some SerializeObject overloads accept null values; settings and Type arguments generally do not).","Enable <Nullable>enable</Nullable> and treat nullable warnings as errors so null arguments are caught at compile time.","Ensure the source feeding the JSON (HTTP client, file read, configuration provider) returns a non-null string by coalescing at the boundary."],"exampleFix":"// before\nvar obj = JsonConvert.DeserializeObject<MyType>(jsonString); // jsonString may be null -> ArgumentNullException (ParamName=\"value\")\n\n// after\nif (jsonString is null) return null;\nvar obj = JsonConvert.DeserializeObject<MyType>(jsonString);","handlingStrategy":"validation","validationCode":"if (jsonString is null)\n    return null; // or: throw your own domain-specific exception\nvar obj = JsonConvert.DeserializeObject<MyType>(jsonString);","typeGuard":"static bool HasJson([NotNullWhen(true)] string? s) => !string.IsNullOrEmpty(s);\n\n// usage\nif (HasJson(jsonString))\n    Deserialize(jsonString);","tryCatchPattern":"try\n{\n    var obj = JsonConvert.DeserializeObject<MyType>(jsonString);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"value\")\n{\n    // jsonString (or the named argument) was null; handle the missing-input case.\n}","preventionTips":["Enable <Nullable>enable</Nullable> and treat nullable warnings as errors to catch null arguments at compile time.","Coalesce nulls at the boundary (jsonString ?? string.Empty) or short-circuit before calling the serializer.","Read the ArgumentNullException.ParamName to identify exactly which argument was null.","Catch ArgumentNullException only when you can genuinely recover; otherwise fix the null at its source (HTTP/file/config reader)."],"tags":["argument-validation","null-reference","argumentnullexception"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}