# Microsoft.AspNetCore.JsonPatch.JsonPatchException: The property at path 'path' could not be updated.

- **ID:** `dotnet/aspnetcore-json-patch-document-invalid`
- **Domain:** dotnet
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A JSON Patch operation (e.g., replace, add, remove) targets a property that does not exist on the target object, or the operation violates model validation rules, often due to incorrect path syntax or missing properties.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 6.0 | active | — | — |
| 7.0 | active | — | — |
| 8.0 | active | — | — |

## Workarounds

1. **Validate the JSON Patch document before applying it: use 'var patchDoc = new JsonPatchDocument<MyModel>(); patchDoc.Operations.Add(new Operation("replace", "/PropertyName", null, "newValue"));' and check that '/PropertyName' exists via reflection or model metadata.** (85% success)
   ```
   Validate the JSON Patch document before applying it: use 'var patchDoc = new JsonPatchDocument<MyModel>(); patchDoc.Operations.Add(new Operation("replace", "/PropertyName", null, "newValue"));' and check that '/PropertyName' exists via reflection or model metadata.
   ```
2. **Apply the patch to a copy of the model and use TryValidateModel to catch validation errors: 'var tempModel = new MyModel(); patchDoc.ApplyTo(tempModel); if (!TryValidateModel(tempModel)) return BadRequest(ModelState);'** (80% success)
   ```
   Apply the patch to a copy of the model and use TryValidateModel to catch validation errors: 'var tempModel = new MyModel(); patchDoc.ApplyTo(tempModel); if (!TryValidateModel(tempModel)) return BadRequest(ModelState);'
   ```

## Dead Ends

- **** — Adding [FromBody] to the action parameter does not fix the patch document; the issue is with the operation path or target model structure. (90% fail)
- **** — Changing the HTTP method from PATCH to PUT may bypass the patch logic but breaks RESTful conventions and can cause unintended full replacement of the resource. (70% fail)
