OrchardCMS/OrchardCore · error · InvalidOperationException

Missing parameter

Error message

Missing parameter: {node.Name}

What it means

When the SQL query parser encounters a @Parameter with no default value and the caller's parameter dictionary does not contain that name, VisitParameter throws this error. SQL queries in Orchard Core require every referenced parameter to be supplied at execution time unless a default literal is declared.

Solutions

  1. Pass the missing key in the parameters dictionary when executing the query
  2. Add a default value in the SQL query, e.g. SET @SomeParam = 'default', so the parser can supply it
  3. Fix the parameter name mismatch between the query text and the caller's dictionary

Example fix

// before
await _queryManager.ExecuteQueryAsync(query); // query uses @Category but no default
// after
await _queryManager.ExecuteQueryAsync(query, new Dictionary<string, object> { ["Category"] = "news" });
Defensive patterns

Strategy: validation

Validate before calling

var missing = queryDoc.Parameters.Where(p => !parameters.ContainsKey(p) && p.DefaultValue is null).ToList();
if (missing.Count > 0) throw new ArgumentException($"Missing query parameters: {string.Join(", ", missing)}");

Try / catch

try { await _queryManager.ExecuteQueryAsync(query, parameters); } catch (InvalidOperationException ex) when (ex.Message.StartsWith("Missing parameter")) { /* surface missing parameter name to caller */ }

Prevention

When it happens

Trigger: Executing a SQL query whose text references @SomeParam, with no default value in the query (no SET @SomeParam = ...) and 'SomeParam' absent from the parameters dictionary passed to the query manager.

Common situations: Calling the Queries API directly and forgetting to add a parameter; renaming a parameter in the SQL but not in the calling code; recipe/template code invoking a query that expects user-supplied parameters.

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


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/4e3e1b1670fd4f21. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Queries/Sql/SqlParser.cs:260

                parts.AddRange(GetTableNameParts(tablePrefix + qualifier.Value));
            }

            for (var i = 1; i < node.Parts.Count; i++)
            {
                parts.Add(Quote(node.Parts[i].Value));
            }

            return node with { Parts = parts };
        }

        protected override SqlNode VisitParameter(ParameterExpression node)
        {
            if (parameters is not null && !parameters.ContainsKey(node.Name))
            {
                parameters[node.Name] = node.DefaultValue switch
                {
                    LiteralExpression { Value: bool or string or decimal or long } literal => literal.Value,
                    null => throw new InvalidOperationException($"Missing parameter: {node.Name}"),
                    _ => throw new InvalidOperationException("Unsupported default parameter value type"),
                };
            }

            return node;
        }

        protected override SqlNode VisitOrderByItem(OrderByItem node)
        {
            var rewritten = (OrderByItem)base.VisitOrderByItem(node);

            return rewritten.Expression is FunctionCallExpression
                {
                    Name.Value: var name,
                    Arguments.Count: 0,
                } function
                && name.Equals("random", StringComparison.OrdinalIgnoreCase)
                    ? rewritten with

View on GitHub (pinned to 4306c0717f)