{"record":{"id":"85656e07212fa68d","repo":"dotnet/efcore","slug":"exactly-one-of-param1-or-param2-must-be-se","errorCode":null,"errorMessage":"Exactly one of '{param1}' or '{param2}' must be set.","messagePattern":"Exactly one of '(.+?)' or '(.+?)' must be set\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/Expressions/InExpression.cs","lineNumber":54,"sourceCode":"    /// </summary>\n    public InExpression(\n        SqlExpression item,\n        SqlParameterExpression valuesParameter,\n        CoreTypeMapping typeMapping)\n        : this(item, values: null, valuesParameter, typeMapping)\n    {\n    }\n\n    private InExpression(\n        SqlExpression item,\n        IReadOnlyList<SqlExpression>? values,\n        SqlParameterExpression? valuesParameter,\n        CoreTypeMapping? typeMapping)\n        : base(typeof(bool), typeMapping)\n    {\n        if ((values is null ? 0 : 1) + (valuesParameter is null ? 0 : 1) != 1)\n        {\n            throw new ArgumentException(\n                CosmosStrings.OneOfTwoValuesMustBeSet(nameof(values), nameof(valuesParameter)));\n        }\n\n        Item = item;\n        Values = values;\n        ValuesParameter = valuesParameter;\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual SqlExpression Item { get; }\n\n    /// <summary>\n    ///     The list of values to search the item in.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/Expressions/InExpression.cs#L36-L72","documentation":"InExpression models `x IN (...)`. Its private constructor enforces that exactly one of two mutually-exclusive value sources is supplied: an inline list (Values) or a single collection parameter (ValuesParameter). Supplying both or neither throws ArgumentException. This is an internal API contract guard, not normally reachable by end users.","triggerScenarios":"Directly constructing InExpression with both values and valuesParameter set, or both null. Reachable only by custom query translators/extensions that build IN expressions, since the public constructors funnel into the private one with exactly one source.","commonSituations":"Writing a custom Cosmos query translator or extending the pipeline with hand-built InExpression nodes; rarely seen by application developers.","solutions":["Pass exactly one of `values` (IReadOnlyList<SqlExpression>) or `valuesParameter` (SqlParameterExpression) to the InExpression constructor.","Prefer the public Update(...) overloads and the SqlExpressionFactory.In(...) helpers, which preserve the invariant.","If you maintain a fork/extension, add a unit test asserting the exactly-one invariant."],"exampleFix":"// before (internal translator bug)\nnew InExpression(item, values, valuesParameter, typeMapping);\n\n// after: choose one source\nnew InExpression(item, values, typeMapping);\n// or\nnew InExpression(item, valuesParameter, typeMapping);","handlingStrategy":"validation","validationCode":"// Internal-only API: assert the exactly-one invariant in tests.\nstatic bool ExactlyOneOf<T>(T? a, T? b) where T : class\n    => (a is null ? 0 : 1) + (b is null ? 0 : 1) == 1;\nDebug.Assert(ExactlyOneOf(values, valuesParameter));","typeGuard":null,"tryCatchPattern":"try { var inExpr = new InExpression(item, values, typeMapping); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"must be set\"))\n{ /* fix the translator to supply exactly one source */ }","preventionTips":["Prefer SqlExpressionFactory.In(...) over constructing InExpression directly.","If you maintain a fork, add a unit test enforcing the exactly-one invariant."],"tags":["cosmos","internal","in-expression","argument-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}