{"record":{"id":"11a9b7de24dcca7e","repo":"JamesNK/Newtonsoft.Json","slug":"error-getting-value-from-0-on-1-11a9b7","errorCode":null,"errorMessage":"Error getting value from '{0}' on '{1}'.","messagePattern":"Error getting value from '(.+?)' on '(.+?)'\\.","errorType":"exception","errorClass":"JsonSerializationException","httpStatus":null,"severity":"error","filePath":"Src/Newtonsoft.Json/Serialization/ExpressionValueProvider.cs","lineNumber":110,"sourceCode":"        /// <summary>\n        /// Gets the value.\n        /// </summary>\n        /// <param name=\"target\">The target to get the value from.</param>\n        /// <returns>The value.</returns>\n        public object? GetValue(object target)\n        {\n            try\n            {\n                if (_getter == null)\n                {\n                    _getter = ExpressionReflectionDelegateFactory.Instance.CreateGet<object>(_memberInfo);\n                }\n\n                return _getter(target);\n            }\n            catch (Exception ex)\n            {\n                throw new JsonSerializationException(\"Error getting value from '{0}' on '{1}'.\".FormatWith(CultureInfo.InvariantCulture, _memberInfo.Name, target.GetType()), ex);\n            }\n        }\n    }\n}\n\n#endif","sourceCodeStart":92,"sourceCodeEnd":116,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Serialization/ExpressionValueProvider.cs#L92-L116","documentation":"Identical to error 221 but from ExpressionValueProvider.GetValue on platforms where the expression-tree provider is active. Wraps the original getter exception as InnerException; '{0}' is the member name, '{1}' the target type.","triggerScenarios":"A property getter throws while serializing, surfaced through the expression-based value provider. Same conditions as 221 but on .NET Core/.NET 5+ runtimes.","commonSituations":"EF/Linq2Sql proxy properties throwing after context disposal, computed properties throwing on null state, porting code from .NET Framework where DynamicValueProvider was used and now ExpressionValueProvider surfaces the failure.","solutions":["Read InnerException for the true getter error.","Add a null/state guard inside the getter or use ShouldSerializeX to skip it.","Decorate the problematic property with [JsonIgnore].","Configure JsonSerializerSettings.Error handler to continue past the failing member."],"exampleFix":"// before\npublic class Entity { public string Name => _lazy.Value.Name; }\nJsonConvert.Serialize(entity); // _lazy throws\n// after\npublic class Entity {\n    public bool ShouldSerializeName() => _lazy.IsValueCreated;\n    public string Name => _lazy.Value.Name;\n}","handlingStrategy":"validation","validationCode":"public bool ShouldSerializeX() => _lazy != null && _lazy.IsValueCreated;","typeGuard":null,"tryCatchPattern":"try { JsonConvert.SerializeObject(obj); }\ncatch (JsonSerializationException ex) when (ex.Message.Contains(\"Error getting value\")) {\n    logger.Error(ex.InnerException, \"getter failed at {Path}\", ex.Path); throw;\n}","preventionTips":["Guard getters against disposed/null resources.","Use conditional serialization (ShouldSerializeX) to skip unsafe members.","Decorate volatile getters with [JsonIgnore].","Use JsonSerializerSettings.Error to recover per-member."],"tags":["serialization","reflection","expression-value-provider","getter"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}