{"record":{"id":"9976fe243e20fe75","repo":"JamesNK/Newtonsoft.Json","slug":"type-9976fe","errorCode":null,"errorMessage":"type","messagePattern":"type","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs","lineNumber":66,"sourceCode":"        public CamelCasePropertyNamesContractResolver()\n        {\n            NamingStrategy = new CamelCaseNamingStrategy\n            {\n                ProcessDictionaryKeys = true,\n                OverrideSpecifiedNames = true\n            };\n        }\n\n        /// <summary>\n        /// Resolves the contract for a given type.\n        /// </summary>\n        /// <param name=\"type\">The type to resolve a contract for.</param>\n        /// <returns>The contract for a given type.</returns>\n        public override JsonContract ResolveContract(Type type)\n        {\n            if (type == null)\n            {\n                throw new ArgumentNullException(nameof(type));\n            }\n\n            // for backwards compatibility the CamelCasePropertyNamesContractResolver shares contracts between instances\n            StructMultiKey<Type, Type> key = new StructMultiKey<Type, Type>(GetType(), type);\n            Dictionary<StructMultiKey<Type, Type>, JsonContract>? cache = _contractCache;\n            if (cache == null || !cache.TryGetValue(key, out JsonContract? contract))\n            {\n                contract = CreateContract(type);\n\n                // avoid the possibility of modifying the cache dictionary while another thread is accessing it\n                lock (TypeContractCacheLock)\n                {\n                    cache = _contractCache;\n                    Dictionary<StructMultiKey<Type, Type>, JsonContract> updatedCache = (cache != null)\n                        ? new Dictionary<StructMultiKey<Type, Type>, JsonContract>(cache)\n                        : new Dictionary<StructMultiKey<Type, Type>, JsonContract>();\n                    updatedCache[key] = contract;\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Serialization/CamelCasePropertyNamesContractResolver.cs#L48-L84","documentation":"CamelCasePropertyNamesContractResolver.ResolveContract throws an ArgumentNullException when its 'type' argument is null (line 66). The resolver cannot build or look up a JsonContract for an unknown type, so the very first statement guards against a null Type. This is the standard argument-validation contract for the method.","triggerScenarios":"Calling resolver.ResolveContract(null) directly, or passing a null Type that flows from reflection/serialization settings into the resolver. Also reachable when a generic serializer helper loses its type argument (e.g. typeof(T) where T is unconstrained and resolves to null at runtime through dynamic dispatch).","commonSituations":"Helpers like SerializeObject<T> where T is inferred as a non-type, deserialization pipelines that derive the type from JSON and pass null when $type is absent, or manually constructing the resolver and forgetting the type argument.","solutions":["Null-check the Type before calling ResolveContract and surface a clearer error upstream.","Fix the caller that produces a null Type (ensure typeof(T) / GetType() never yields null before reaching the resolver).","If the type genuinely depends on input, fall back to a default type (e.g. typeof(object)) instead of null."],"exampleFix":"// before\nJsonContract contract = resolver.ResolveContract(maybeNullType);\n\n// after\nif (maybeNullType == null) throw new InvalidOperationException(\"Type was not resolved from input.\");\nJsonContract contract = resolver.ResolveContract(maybeNullType);","handlingStrategy":"validation","validationCode":"if (type == null) throw new ArgumentNullException(nameof(type));\nvar contract = resolver.ResolveContract(type);","typeGuard":"static bool IsResolvableType(Type? t) => t != null && !t.IsPointer && !t.IsByRef;","tryCatchPattern":"try { var contract = resolver.ResolveContract(type); }\ncatch (ArgumentNullException) when (type == null)\n{\n    // log and return a safe default contract or rethrow with context\n}","preventionTips":["Always null-check the Type before resolving a contract.","Trace where the Type originates (reflection, $type, generic inference) and ensure it is never null."],"tags":["argument-null","contract-resolution","validation"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}