JamesNK/Newtonsoft.Json · error · JsonSerializationException
Error getting value from '{0}' on '{1}'.
Error message
Error getting value from '{0}' on '{1}'. What it means
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.
Source
Thrown at Src/Newtonsoft.Json/Serialization/ExpressionValueProvider.cs:110
/// <summary>
/// Gets the value.
/// </summary>
/// <param name="target">The target to get the value from.</param>
/// <returns>The value.</returns>
public object? GetValue(object target)
{
try
{
if (_getter == null)
{
_getter = ExpressionReflectionDelegateFactory.Instance.CreateGet<object>(_memberInfo);
}
return _getter(target);
}
catch (Exception ex)
{
throw new JsonSerializationException("Error getting value from '{0}' on '{1}'.".FormatWith(CultureInfo.InvariantCulture, _memberInfo.Name, target.GetType()), ex);
}
}
}
}
#endifView on GitHub (pinned to 4f73e74372)
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.
Example fix
// before
public class Entity { public string Name => _lazy.Value.Name; }
JsonConvert.Serialize(entity); // _lazy throws
// after
public class Entity {
public bool ShouldSerializeName() => _lazy.IsValueCreated;
public string Name => _lazy.Value.Name;
} Defensive patterns
Strategy: validation
Validate before calling
public bool ShouldSerializeX() => _lazy != null && _lazy.IsValueCreated;
Try / catch
try { JsonConvert.SerializeObject(obj); }
catch (JsonSerializationException ex) when (ex.Message.Contains("Error getting value")) {
logger.Error(ex.InnerException, "getter failed at {Path}", ex.Path); throw;
} Prevention
- 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.
When it happens
Trigger: A property getter throws while serializing, surfaced through the expression-based value provider. Same conditions as 221 but on .NET Core/.NET 5+ runtimes.
Common situations: 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.
Related errors
- Error getting value from '{0}' on '{1}'.
- Error setting value to '{0}' on '{1}'.
- Error getting value from '{0}' on '{1}'.
- Error setting value to '{0}' on '{1}'.
- Could not create getter for {0}. ByRef return values are not
AI-assisted analysis of JamesNK/Newtonsoft.Json@4f73e74372 (2026-08-07).
Data as JSON: /api/errors/11a9b7de24dcca7e.
Report an issue: GitHub.