{"record":{"id":"ebe957feed55b055","repo":"LykosAI/StabilityMatrix","slug":"batchsize-card-is-null","errorCode":null,"errorMessage":"BatchSize card is null","messagePattern":"BatchSize card is null","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Models/InferenceProjectDocument.cs","lineNumber":122,"sourceCode":"        if (!state.TryGetPropertyValue(key, out var modelNode) || modelNode is null)\n        {\n            return false;\n        }\n\n        state[key] = modifier(modelNode);\n\n        return true;\n    }\n\n    public InferenceProjectDocument WithBatchSize(int batchSize, int batchCount)\n    {\n        if (State is null)\n            throw new InvalidOperationException(\"State is null\");\n\n        var document = (InferenceProjectDocument)Clone();\n\n        var batchSizeCard =\n            document.State![\"BatchSize\"] ?? throw new InvalidOperationException(\"BatchSize card is null\");\n\n        batchSizeCard[\"BatchSize\"] = batchSize;\n        batchSizeCard[\"BatchCount\"] = batchCount;\n\n        return document;\n    }\n\n    /// <inheritdoc />\n    public object Clone()\n    {\n        var newObj = (InferenceProjectDocument)MemberwiseClone();\n        // Clone State also since its mutable\n        newObj.State = State == null ? null : JsonSerializer.SerializeToNode(State).Deserialize<JsonObject>();\n        return newObj;\n    }\n}\n","sourceCodeStart":104,"sourceCodeEnd":139,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Models/InferenceProjectDocument.cs#L104-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"Documents edited externally where the BatchSize card was removed; older project formats missing newer cards; programmatically built states that omit standard cards.","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."],"exampleFix":"// before\ndoc.State[\"BatchSize\"] // null -> throws\n// after\ndoc.State[\"BatchSize\"] ??= new JObject\n{\n    [\"BatchSize\"] = 1,\n    [\"BatchCount\"] = 1\n};\ndoc = doc.WithBatchSize(4, 2);","handlingStrategy":"validation","validationCode":"if (doc.State?[\"BatchSize\"] is null)\n    throw new InvalidOperationException(\"Document state lacks a BatchSize card\");","typeGuard":"bool HasBatchSizeCard(InferenceProjectDocument d) =>\n    d.State?[\"BatchSize\"] is not null;","tryCatchPattern":"try { doc = doc.WithBatchSize(4, 2); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"BatchSize card\"))\n{ doc = doc.WithDefaultCards(); doc = doc.WithBatchSize(4, 2); }","preventionTips":["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."],"tags":["missing-card","project-document","state"],"backgroundTag":"missing-required-config-field","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}