elsa-workflows/elsa-core · error · ArgumentException
A conversation user ID is required. (Parameter…
Error message
A conversation user ID is required. (Parameter 'conversation')
What it means
InMemoryAIConversationStore.Validate requires every conversation passed to SaveAsync to have a non-whitespace UserId. The user ID is used for ownership checks, so an ArgumentException naming the 'conversation' parameter is thrown when it is missing.
Solutions
- Set conversation.UserId to the owning user's ID before saving.
- Ensure user-context resolution populates UserId before store calls.
- Validate the mapped object before invoking the store.
Example fix
// before
await store.SaveAsync(new AIConversation { Id = id });
// after
await store.SaveAsync(new AIConversation { Id = id, UserId = currentUserId }); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(conversation.UserId)) throw new ArgumentException("Conversation UserId required"); Type guard
bool HasUser(AIConversation c) => !string.IsNullOrWhiteSpace(c.UserId);
Try / catch
try { await store.SaveAsync(conversation); } catch (ArgumentException ex) when (ex.ParamName == "conversation") { logger.LogError(ex, "Conversation missing UserId"); } Prevention
- Resolve the current user before constructing the conversation.
- Reject userless conversations at the API boundary.
- Add unit tests covering null/empty UserId saves.
When it happens
Trigger: Calling SaveAsync with an AIConversation whose UserId is null, empty, or whitespace.
Common situations: Tests constructing conversations without setting UserId; losing the current-user context so UserId defaults to null; deserializing conversations from payloads that omit the user field.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- A conversation ID is required. (Parameter 'conversation')
- Invalid value type.
- Cannot overwrite an AI conversation that belongs to another…
- Cannot overwrite an AI conversation that belongs to another…
- A conversation ID is required. (Parameter 'conversation')
AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13).
Data as JSON: /api/errors/7752b5265caa0b6b.
Report an issue: GitHub.
Appendix: source
Thrown at src/modules/Elsa.AI.Host/Services/InMemoryAIConversationStore.cs:74
private static void ValidateOwnership(AIConversation existing, AIConversation conversation)
{
if (!string.Equals(NormalizeTenantId(existing.TenantId), NormalizeTenantId(conversation.TenantId), StringComparison.Ordinal))
throw new InvalidOperationException("Cannot overwrite an AI conversation that belongs to another tenant.");
if (!string.IsNullOrWhiteSpace(existing.UserId) && !string.Equals(existing.UserId, conversation.UserId, StringComparison.Ordinal))
throw new InvalidOperationException("Cannot overwrite an AI conversation that belongs to another user.");
}
private static string NormalizeTenantId(string? tenantId) => tenantId ?? "";
private static void Validate(AIConversation conversation)
{
if (string.IsNullOrWhiteSpace(conversation.Id))
throw new ArgumentException("A conversation ID is required.", nameof(conversation));
if (string.IsNullOrWhiteSpace(conversation.UserId))
throw new ArgumentException("A conversation user ID is required.", nameof(conversation));
}
}
View on GitHub (pinned to fe9217bdfa)