LykosAI/StabilityMatrix · error · InvalidOperationException
BatchSize card is null
Error message
BatchSize card is null
What it means
WithBatchSize() looks up a 'BatchSize' node/card inside the document State JSON and throws InvalidOperationException('BatchSize card is null') when that key is missing or its value is null. The method assumes a standard inference state layout containing a BatchSize card.
Solutions
- Ensure the project state contains a BatchSize card (recreate via the default state template).
- Add the 'BatchSize' card to State before calling WithBatchSize, or set batch values directly on State.
- Verify state schema on load and repair/upgrade missing standard cards.
- Catch InvalidOperationException and fall back to direct State manipulation.
Example fix
// before
doc.State["BatchSize"] // null -> throws
// after
doc.State["BatchSize"] ??= new JObject
{
["BatchSize"] = 1,
["BatchCount"] = 1
};
doc = doc.WithBatchSize(4, 2); Defensive patterns
Strategy: validation
Validate before calling
if (doc.State?["BatchSize"] is null)
throw new InvalidOperationException("Document state lacks a BatchSize card"); Type guard
bool HasBatchSizeCard(InferenceProjectDocument d) =>
d.State?["BatchSize"] is not null; Try / catch
try { doc = doc.WithBatchSize(4, 2); }
catch (InvalidOperationException ex) when (ex.Message.Contains("BatchSize card"))
{ doc = doc.WithDefaultCards(); doc = doc.WithBatchSize(4, 2); } Prevention
- Use the default state template as the base for all programmatic documents.
- Validate state schema (required cards present) right after load or external edits.
- Avoid deleting standard cards (BatchSize, resolution, etc.) when pruning the graph.
When it happens
Trigger: Calling WithBatchSize() on a document whose State exists but lacks a 'BatchSize' entry — e.g. a custom/minimal state, a state where the BatchSize node was deleted, or a state created by a different app version.
Common situations: Documents edited externally where the BatchSize card was removed; older project formats missing newer cards; programmatically built states that omit standard cards.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- State is null
- Lykos account must be connected in to manage OAuth…
- Client is not connected
- Venv already exists
- Conversation not found
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/ebe957feed55b055.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Avalonia/Models/InferenceProjectDocument.cs:122
if (!state.TryGetPropertyValue(key, out var modelNode) || modelNode is null)
{
return false;
}
state[key] = modifier(modelNode);
return true;
}
public InferenceProjectDocument WithBatchSize(int batchSize, int batchCount)
{
if (State is null)
throw new InvalidOperationException("State is null");
var document = (InferenceProjectDocument)Clone();
var batchSizeCard =
document.State!["BatchSize"] ?? throw new InvalidOperationException("BatchSize card is null");
batchSizeCard["BatchSize"] = batchSize;
batchSizeCard["BatchCount"] = batchCount;
return document;
}
/// <inheritdoc />
public object Clone()
{
var newObj = (InferenceProjectDocument)MemberwiseClone();
// Clone State also since its mutable
newObj.State = State == null ? null : JsonSerializer.SerializeToNode(State).Deserialize<JsonObject>();
return newObj;
}
}
View on GitHub (pinned to af93d6ef57)