{"record":{"id":"3da9929ab8a380d2","repo":"JamesNK/Newtonsoft.Json","slug":"accessed-jconstructor-values-with-invalid-key-valu","errorCode":null,"errorMessage":"Accessed JConstructor values with invalid key value: {0}. Argument position index expected.","messagePattern":"Accessed JConstructor values with invalid key value: (.+?)\\. Argument position index expected\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Linq/JConstructor.cs","lineNumber":194,"sourceCode":"                _values[i].WriteTo(writer, converters);\n            }\n\n            writer.WriteEndConstructor();\n        }\n\n        /// <summary>\n        /// Gets the <see cref=\"JToken\"/> with the specified key.\n        /// </summary>\n        /// <value>The <see cref=\"JToken\"/> with the specified key.</value>\n        public override JToken? this[object key]\n        {\n            get\n            {\n                ValidationUtils.ArgumentNotNull(key, nameof(key));\n\n                if (!(key is int i))\n                {\n                    throw new ArgumentException(\"Accessed JConstructor values with invalid key value: {0}. Argument position index expected.\".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key)));\n                }\n\n                return GetItem(i);\n            }\n            set\n            {\n                ValidationUtils.ArgumentNotNull(key, nameof(key));\n\n                if (!(key is int i))\n                {\n                    throw new ArgumentException(\"Set JConstructor values with invalid key value: {0}. Argument position index expected.\".FormatWith(CultureInfo.InvariantCulture, MiscellaneousUtils.ToString(key)));\n                }\n\n                SetItem(i, value);\n            }\n        }\n\n        internal override int GetDeepHashCode()","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Linq/JConstructor.cs#L176-L212","documentation":"Thrown by the JConstructor[object key] getter when the key is not an int. JConstructor arguments are positional (unlike JProperty), so only integer argument positions are accepted.","triggerScenarios":"Indexing a JConstructor with a string or any non-int key on the read side.","commonSituations":"Assuming JConstructor supports named lookup like JObject; dynamic key dispatch.","solutions":["Use an integer argument position: ctor[0].","Iterate Children() to find a specific argument by value.","Re-check whether you actually need a JObject for named access."],"exampleFix":"// before\nJToken a = myCtor[(object)\"x\"];\n// after\nJToken a = myCtor[0];","handlingStrategy":"type-guard","validationCode":"if (key is int i) { JToken v = ctor[i]; }\nelse throw new InvalidOperationException(\"JConstructor requires an int argument index.\");","typeGuard":"static bool IsCtorKey(object key) => key is int;","tryCatchPattern":"try { var v = ctor[key]; }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Argument position index expected\")) {\n    // fall back to integer index\n}","preventionTips":["Always use integer positions for JConstructor arguments.","Remember JConstructor is positional, not keyed.","Wrap dynamic keys in an int-coercion check."],"tags":["jconstructor","indexer","argument"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}