JustArchiNET/ArchiSteamFarm · error · JsonException
Required field {field.Name} expects a non-null value.
Error message
Required field {field.Name} expects a non-null value. What it means
Thrown by OnPotentialDisallowedNullsDeserialized, a System.Text.Json OnDeserialized callback wired onto every JsonTypeInfo (JsonUtilities.cs:114). After an object graph is deserialized, ASF scans all fields decorated with [JsonDisallowNullAttribute]; if any such field is still null, a JsonException is raised with the offending field name. It enforces that critical config fields (e.g. on GlobalConfig/BotConfig) can never silently deserialize to null.
Source
Thrown at ArchiSteamFarm/Helpers/Json/JsonUtilities.cs:184
if (string.IsNullOrEmpty(memberName) || (memberName == property.Name)) {
// We don't have anything to work with further, there is no ShouldSerialize() method
return null;
}
result = parent.GetMethod($"ShouldSerialize{memberName}", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static, null, Type.EmptyTypes, null);
// Use alternative method if it exists and returns a boolean
return result?.ReturnType == typeof(bool) ? result : null;
}
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2075", Justification = "We don't care about trimmed properties, it's not like we can make it work differently anyway")]
private static void OnPotentialDisallowedNullsDeserialized(object obj) {
ArgumentNullException.ThrowIfNull(obj);
Type type = obj.GetType();
foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).Where(field => field.IsDefined(typeof(JsonDisallowNullAttribute), false) && (field.GetValue(obj) == null))) {
throw new JsonException($"Required field {field.Name} expects a non-null value.");
}
foreach (PropertyInfo property in type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static).Where(property => (property.GetMethod != null) && property.IsDefined(typeof(JsonDisallowNullAttribute), false) && (property.GetValue(obj) == null))) {
throw new JsonException($"Required property {property.Name} expects a non-null value.");
}
}
private static bool ShouldSerialize(MethodInfo shouldSerializeMethod, object parent) {
ArgumentNullException.ThrowIfNull(shouldSerializeMethod);
ArgumentNullException.ThrowIfNull(parent);
if (shouldSerializeMethod.ReturnType != typeof(bool)) {
throw new InvalidOperationException(nameof(shouldSerializeMethod));
}
object? shouldSerialize = shouldSerializeMethod.Invoke(parent, null);
if (shouldSerialize is not bool result) {View on GitHub (pinned to fe57c4129f)
Solutions
- Open the config file named in the bot/log and add the missing field with a valid non-null value.
- If unsure of the schema, regenerate the config from ASF's default/template config or delete it so ASF recreates a valid one.
- Upgrade to a matching ASF version so field names/types align with the config schema.
- Validate the JSON with a parser (jsonlint) to rule out a syntax error that made the field silently null.
Example fix
// before (bot JSON)
{ "Enabled": true }
// after (add the disallowed-null field the error names)
{ "Enabled": true, "SteamLogin": "myaccount" } Defensive patterns
Strategy: validation
Validate before calling
// Validate config object has no null [JsonDisallowNull] members before use.
var json = File.ReadAllText(configPath);
using JsonDocument doc = JsonDocument.Parse(json);
foreach (JsonProperty prop in doc.RootElement.EnumerateObject()) {
if (configuredRequiredFields.Contains(prop.Name) &&
prop.Value.ValueKind == JsonValueKind.Null) {
throw new InvalidOperationException($"Config '{prop.Name}' is null in {configPath}");
}
} Try / catch
try { MyConfig cfg = JsonSerializer.Deserialize<MyConfig>(json, ArchiSteamFarm.Options)!; }
catch (JsonException ex) when (ex.Message.Contains("expects a non-null value")) {
// surface the offending field name from the message and report config issue
logger.LogError(ex, "Config missing a required field");
} Prevention
- Always edit ASF config through ASF's own generation rather than hand-editing JSON.
- Keep a known-good config backup to diff against when this fires.
- Run the ASF build whose schema matches the config files you deploy.
When it happens
Trigger: Deserializing a JSON config object (bot .json, GlobalConfig, GlobalDatabase) that omits a required field, supplies it as JSON null, or whose value fails to bind to the field's type so System.Text.Json leaves it null. The check fires only on types/members carrying JsonDisallowNullAttribute.
Common situations: A user hand-edits a bot config and removes a mandatory key; a field was renamed between ASF versions but the old config was kept; JSON casing/serialization options mismatch caused a property to deserialize as null; migration from an older config that lacks a newly-required field.
Related errors
- Required property {property.Name} expects a non-null value.
- SteamID is invalid!
- Received unknown value for {0}, please report this: {1}
- steamID is null!
AI-assisted analysis of JustArchiNET/ArchiSteamFarm@fe57c4129f (2026-08-13).
Data as JSON: /api/errors/c6d87e2abe548b3b.
Report an issue: GitHub.