{"record":{"id":"8b41c4206e5f9097","repo":"JamesNK/Newtonsoft.Json","slug":"could-not-resolve-schema-reference-0","errorCode":null,"errorMessage":"Could not resolve schema reference '{0}'.","messagePattern":"Could not resolve schema reference '(.+?)'\\.","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs","lineNumber":152,"sourceCode":"                                    currentToken = null;\n                                }\n                            }\n\n                            if (currentToken == null)\n                            {\n                                break;\n                            }\n                        }\n\n                        if (currentToken != null)\n                        {\n                            resolvedSchema = BuildSchema(currentToken);\n                        }\n                    }\n\n                    if (resolvedSchema == null)\n                    {\n                        throw new JsonException(\"Could not resolve schema reference '{0}'.\".FormatWith(CultureInfo.InvariantCulture, schema.DeferredReference));\n                    }\n                }\n\n                schema = resolvedSchema;\n            }\n\n            if (schema.ReferencesResolved)\n            {\n                return schema;\n            }\n\n            schema.ReferencesResolved = true;\n\n            if (schema.Extends != null)\n            {\n                for (int i = 0; i < schema.Extends.Count; i++)\n                {\n                    schema.Extends[i] = ResolveReferences(schema.Extends[i]);","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Schema/JsonSchemaBuilder.cs#L134-L170","documentation":"Thrown by JsonSchemaBuilder.ResolveReferences when a $ref (or extends) pointer cannot be resolved: it is not found in the resolver's loaded schemas and, for '#'-prefixed location references, the JSON pointer walk through the root document failed (the target path does not exist in the schema document).","triggerScenarios":"Loading a JSON Schema whose $ref points to a non-existent id or JSON pointer. Examples: JsonSchema.Parse(\"{\\\"$ref\\\":\\\"#unknown\\\"}\") (pointer target missing), or a $ref to an external id that was never registered with the shared JsonSchemaResolver.","commonSituations":"Splitting a schema across files but not sharing a JsonSchemaResolver between reads; typos in $ref pointers; renaming a definition without updating references; cross-document $ref where the referenced document was not loaded first.","solutions":["Share one JsonSchemaResolver instance across all JsonSchema.Read/Parse calls so referenced ids are registered.","Verify the $ref target exists in the document (correct JSON pointer like #/definitions/foo).","Load referenced external schemas before the schema that points to them."],"exampleFix":"// before\nvar s1 = JsonSchema.Parse(\"{\\\"id\\\":\\\"root\\\",\\\"items\\\":{\\\"$ref\\\":\\\"#missing\\\"}}\");\n// after\nvar s1 = JsonSchema.Parse(\"{\\\"id\\\":\\\"root\\\",\\\"definitions\\\":{\\\"i\\\":{}},\\\"items\\\":{\\\"$ref\\\":\\\"#/definitions/i\\\"}}\");","handlingStrategy":"validation","validationCode":"static JsonSchemaResolver LoadAll(IEnumerable<string> schemaJsons)\n{\n    var resolver = new JsonSchemaResolver();\n    foreach (var json in schemaJsons) JsonSchema.Parse(json, resolver);\n    return resolver;\n}","typeGuard":null,"tryCatchPattern":"try { JsonSchema.Parse(json, resolver); }\ncatch (JsonException ex) when (ex.Message.StartsWith(\"Could not resolve schema reference\"))\n{ /* $ref target missing; load referenced schema or fix the pointer */ }","preventionTips":["Share a single JsonSchemaResolver across related schema loads.","Verify $ref JSON pointers exist under definitions/id before parsing.","Load referenced external schemas first."],"tags":["schema","json","reference","jsonschema","resolution"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}