{"record":{"id":"94286fdc5e978b1c","repo":"JamesNK/Newtonsoft.Json","slug":"error-getting-value-from-0-on-1-94286f","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/ReflectionValueProvider.cs","lineNumber":86,"sourceCode":"        /// 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                // https://github.com/dotnet/corefx/issues/26053\n                if (_memberInfo is PropertyInfo propertyInfo && propertyInfo.PropertyType.IsByRef)\n                {\n                    throw new InvalidOperationException(\"Could not create getter for {0}. ByRef return values are not supported.\".FormatWith(CultureInfo.InvariantCulture, propertyInfo));\n                }\n\n                return ReflectionUtils.GetMemberValue(_memberInfo, 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}","sourceCodeStart":68,"sourceCodeEnd":90,"githubUrl":"https://github.com/JamesNK/Newtonsoft.Json/blob/4f73e74372445108d2c1bda37b36e6f5e43402e0/Src/Newtonsoft.Json/Serialization/ReflectionValueProvider.cs#L68-L90","documentation":"Thrown by ReflectionValueProvider.GetValue when ReflectionUtils.GetMemberValue throws while reading a member from the target object. '{0}' is the member name, '{1}' the target type; the original exception is attached as InnerException. This is the reflection-fallback counterpart of errors 221/223.","triggerScenarios":"Serializing an object where reading a field/property via reflection fails: a property getter that throws (NullReferenceException, ObjectDisposedException, etc.), or attempting to read a member that reflection cannot access.","commonSituations":"EF/proxy property getters throwing after context disposal, computed properties throwing on bad state, restricted reflection environments, or serializing interop types with inaccessible members.","solutions":["Inspect InnerException to find the real getter exception.","Guard the getter against null/disposed state or wrap the body to never throw during serialization.","Skip the property with [JsonIgnore] or conditional serialization (ShouldSerializeX).","Configure JsonSerializerSettings.Error to log and continue past the failing member."],"exampleFix":"// before: getter throws\npublic class Conn { public Stream Stream => _disposed ? throw new ObjectDisposedException(\"x\") : _s; }\nJsonConvert.Serialize(conn);\n// after\npublic class Conn {\n    public bool ShouldSerializeStream() => !_disposed;\n    public Stream Stream => _disposed ? null : _s;\n}","handlingStrategy":"validation","validationCode":"public bool ShouldSerializeX() => !_disposed && _inner != null;","typeGuard":null,"tryCatchPattern":"try { JsonConvert.SerializeObject(obj); }\ncatch (JsonSerializationException ex) when (ex.Message.Contains(\"Error getting value\")) {\n    logger.Error(ex.InnerException, \"reflection getter failed at {Path}\", ex.Path); throw;\n}","preventionTips":["Guard getters against null/disposed dependencies.","Use ShouldSerializeX to skip members in unsafe state.","Decorate volatile getters with [JsonIgnore].","Configure JsonSerializerSettings.Error to recover per-member."],"tags":["serialization","reflection","reflection-value-provider","getter"],"analyzedSha":"4f73e74372445108d2c1bda37b36e6f5e43402e0","analyzedAt":"2026-08-07T06:10:08.596Z","schemaVersion":2},"datasetVersion":"2026-08-07T07:17:06.508Z"}