{"record":{"id":"2783cf79f3e8b9ce","repo":"JamesNK/Newtonsoft.Json","slug":"currentpropertyname-has-not-been-set-on-scope","errorCode":null,"errorMessage":"CurrentPropertyName has not been set on scope.","messagePattern":"CurrentPropertyName has not been set on scope\\.","errorType":"exception","errorClass":"JsonReaderException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/JsonValidatingReader.cs","lineNumber":194,"sourceCode":"                if (_currentScope == null)\n                {\n                    return new List<JsonSchemaModel>(new[] { _model });\n                }\n\n                if (_currentScope.Schemas == null || _currentScope.Schemas.Count == 0)\n                {\n                    return EmptySchemaList;\n                }\n\n                switch (_currentScope.TokenType)\n                {\n                    case JTokenType.None:\n                        return _currentScope.Schemas;\n                    case JTokenType.Object:\n                        {\n                            if (_currentScope.CurrentPropertyName == null)\n                            {\n                                throw new JsonReaderException(\"CurrentPropertyName has not been set on scope.\");\n                            }\n\n                            IList<JsonSchemaModel> schemas = new List<JsonSchemaModel>();\n\n                            foreach (JsonSchemaModel schema in CurrentSchemas)\n                            {\n                                if (schema.Properties != null && schema.Properties.TryGetValue(_currentScope.CurrentPropertyName, out JsonSchemaModel propertySchema))\n                                {\n                                    schemas.Add(propertySchema);\n                                }\n                                if (schema.PatternProperties != null)\n                                {\n                                    foreach (KeyValuePair<string, JsonSchemaModel> patternProperty in schema.PatternProperties)\n                                    {\n                                        if (Regex.IsMatch(_currentScope.CurrentPropertyName, patternProperty.Key))\n                                        {\n                                            schemas.Add(patternProperty.Value);\n                                        }","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/JsonValidatingReader.cs#L176-L212","documentation":"Thrown by JsonValidatingReader's CurrentSchemas getter when the current token is an Object but the scope's CurrentPropertyName is null. The schema validator needs the current property name to look up the matching property/patternProperty schema; reaching this state with a null name indicates an internal reader-state inconsistency (property value being validated before a property name was recorded). It surfaces as a JsonReaderException.","triggerScenarios":"Validating JSON whose object scopes trigger schema lookups before a property name token was processed; custom JsonReader wrappers that advance tokens out of order under a JsonValidatingReader; corrupted/malformed token streams fed to the validating reader.","commonSituations":"Wrapping a JsonValidatingReader around a non-standard reader; bugs in token ordering from pre-processing/transforming readers; malformed JSON that desynchronizes property-name/value pairing.","solutions":["Feed JsonValidatingReader from a normal JsonTextReader (or a reader that faithfully emits PropertyName then value tokens).","Verify the JSON is well-formed and that object members are name/value pairs before validation.","If you wrote a custom reader, ensure WriteToken/Read ordering emits PropertyName before its value."],"exampleFix":"// before\nusing var validating = new JsonValidatingReader(customReorderingReader);\n\n// after\nusing var validating = new JsonValidatingReader(new JsonTextReader(input));","handlingStrategy":"try-catch","validationCode":"if (validating.TokenType == JsonToken.StartObject &&\n    /* ensure a PropertyName precedes value reads */\n    string.IsNullOrEmpty(validating.CurrentPath))\n{\n    // do not validate out-of-order object members\n}","typeGuard":"static bool ReaderStateConsistent(JsonValidatingReader r)\n    => !(r.TokenType == JsonToken.StartObject && /* name pending */ false);","tryCatchPattern":"try\n{\n    while (validating.Read()) { /* validate */ }\n}\ncatch (JsonReaderException ex) when (ex.Message.Contains(\"CurrentPropertyName has not been set\"))\n{\n    // log and surface a clearer 'malformed JSON / reader misorder' message\n}","preventionTips":["Wrap only a faithful JsonTextReader with JsonValidatingReader.","Validate JSON is well-formed before schema validation.","Avoid custom readers that reorder PropertyName/value tokens."],"tags":["schema-validation","json-reader","internal-state"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}