{"record":{"id":"1c962036b4bc03cd","repo":"elsa-workflows/elsa-core","slug":"stored-secret-document-document-id-could-not-be-deserialized","errorCode":null,"errorMessage":"Stored secret document '{document.Id}' could not be deserialized.","messagePattern":"Stored secret document '(.+?)' could not be deserialized\\.","errorType":"exception","errorClass":"DocumentStoreValidationException","httpStatus":null,"severity":"critical","filePath":"src/modules/Elsa.Secrets.Persistence.VNext/Repositories/VNextSecretRepository.cs","lineNumber":133,"sourceCode":"            StorageUnitName,\n            NormalizeDocumentId(secret.Name),\n            JsonSerializer.Serialize(secret, _jsonOptions),\n            CreateIndexValues(secret),\n            expectedVersion);\n\n        await documentStore.SaveAsync(request, cancellationToken);\n    }\n\n    private async Task<(StoredDocument Document, Secret Secret)?> LoadDocumentAsync(string name, CancellationToken cancellationToken)\n    {\n        var document = await documentStore.LoadAsync(StorageUnitName, NormalizeDocumentId(name), cancellationToken);\n        return document is null ? null : (document, Deserialize(document));\n    }\n\n    private Secret Deserialize(StoredDocument document)\n    {\n        return JsonSerializer.Deserialize<Secret>(document.Content, _jsonOptions)\n            ?? throw new DocumentStoreValidationException($\"Stored secret document '{document.Id}' could not be deserialized.\");\n    }\n\n    private static Dictionary<string, string?> CreateIndexValues(Secret secret)\n    {\n        return new()\n        {\n            [nameof(Secret.Name)] = secret.Name,\n            [nameof(Secret.TypeName)] = secret.TypeName,\n            [nameof(Secret.StoreName)] = secret.StoreName,\n            [nameof(Secret.Scope)] = secret.Scope,\n            [nameof(Secret.Status)] = secret.Status.ToString()\n        };\n    }\n\n    private static string NormalizeDocumentId(string name)\n    {\n        return name.Trim().ToLowerInvariant();\n    }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Secrets.Persistence.VNext/Repositories/VNextSecretRepository.cs#L115-L151","documentation":"When loading a stored secret document, the repository JSON-deserializes the stored Content into a Secret using its configured serializer options. If the JSON is null/corrupt or does not deserialize to a Secret, it throws DocumentStoreValidationException. This protects callers from silently receiving a null Secret from damaged storage data.","triggerScenarios":"Calling GetAsync (or any read path via LoadDocumentAsync) on a stored document whose Content was written by an incompatible serializer version, manually edited, truncated, or whose schema no longer matches the current Secret type.","commonSituations":"Upgrading Elsa between versions where the stored Secret JSON schema changed; DB rows edited by hand or by external tooling; a migration or backup/restore that corrupted document content.","solutions":["Inspect the stored document Content in the database and fix or remove the corrupt row.","Re-create the affected secret (delete the bad document, then add the secret again).","Check for a version mismatch: data written by an older/newer Elsa version may need migration.","Restore the document from a backup if the value cannot be reconstructed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// If you own the stored content, pre-check it:\ntry { using var _ = JsonDocument.Parse(content); } catch (JsonException) { throw new InvalidOperationException(\"Stored secret JSON is invalid.\"); }","typeGuard":"bool IsValidStoredSecretJson(string content) { try { return JsonSerializer.Deserialize<JsonElement>(content).ValueKind == JsonValueKind.Object; } catch (JsonException) { return false; } }","tryCatchPattern":"try { var secret = await secretRepository.GetAsync(id, ct); }\ncatch (DocumentStoreValidationException ex) { logger.LogError(ex, \"Corrupt secret document {Id}\", id); /* skip, repair, or fail fast */ }","preventionTips":["Do not edit secret documents in the database directly.","Back up data before upgrading Elsa versions.","Validate stored JSON after manual migrations or restores."],"tags":["json","deserialization","data-corruption","persistence"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}