{"record":{"id":"0a6a91d46196261b","repo":"AvaloniaUI/Avalonia","slug":"need-more-than-one-query-to-or","errorCode":null,"errorMessage":"Need more than one query to OR.","messagePattern":"Need more than one query to OR\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Styling/OrQuery.cs","lineNumber":31,"sourceCode":"    internal sealed class OrQuery : StyleQuery\n    {\n        private readonly IReadOnlyList<StyleQuery> _queries;\n        private string? _queryString;\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"OrQuery\"/> class.\n        /// </summary>\n        /// <param name=\"queries\">The querys to OR.</param>\n        public OrQuery(IReadOnlyList<StyleQuery> queries)\n        {\n            if (queries is null)\n            {\n                throw new ArgumentNullException(nameof(queries));\n            }\n\n            if (queries.Count <= 1)\n            {\n                throw new ArgumentException(\"Need more than one query to OR.\");\n            }\n\n            _queries = queries;\n        }\n\n        /// <inheritdoc/>\n        internal override bool IsCombinator => false;\n\n        /// <inheritdoc/>\n        public override string ToString(ContainerQuery? owner)\n        {\n            if (_queryString == null)\n            {\n                _queryString = string.Join(\", \", _queries.Select(x => x.ToString(owner)));\n            }\n\n            return _queryString;\n        }","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Styling/OrQuery.cs#L13-L49","documentation":"Thrown by the OrQuery constructor (container-query OR group) when the supplied query list has zero or one elements. A logical OR is only meaningful with at least two operands, so fewer is treated as a programming error rather than silently returning the single query.","triggerScenarios":"Constructing an OrQuery directly with an empty or single-element list, or producing a container query OR group via a factory/builder that ends up with fewer than two queries (e.g. filtering removed queries).","commonSituations":"Programmatically building container queries and OR-ing a list that was dynamically filtered down to one or zero elements; passing `Array.Empty<StyleQuery>()` by mistake.","solutions":["Ensure at least two StyleQuery instances are passed to the OrQuery constructor.","If the list is dynamic, short-circuit: if only one query remains, use it directly instead of wrapping in OrQuery; if zero, skip.","Validate the count before constructing."],"exampleFix":"// before\nvar orq = new OrQuery(filteredQueries); // filteredQueries may have <=1 element\n\n// after\nStyleQuery result = filteredQueries.Count switch\n{\n    0 => throw new InvalidOperationException(\"no queries\"),\n    1 => filteredQueries[0],\n    _ => new OrQuery(filteredQueries)\n};","handlingStrategy":"validation","validationCode":"if (queries is null || queries.Count < 2)\n    throw new ArgumentException(\"OrQuery requires at least two queries.\", nameof(queries));\nvar orq = new OrQuery(queries);","typeGuard":"static bool CanOr(IReadOnlyList<StyleQuery> q) => q is { Count: >= 2 };","tryCatchPattern":null,"preventionTips":["When dynamically building OR query lists, short-circuit to the single query when only one remains.","Validate list length before constructing OrQuery.","Avoid passing filtered lists without a count check."],"tags":["avalonia","styling","or-query","container-query","validation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}