OrchardCMS/OrchardCore · error · InvalidOperationException

Unsupported default parameter value type

Error message

Unsupported default parameter value type

What it means

The SQL query parser only accepts default parameter values that are literal bool, string, decimal, or long expressions. If a @Parameter has a default of another type (e.g. a nested expression, date, or numeric form the parser doesn't classify) it throws this InvalidOperationException.

Solutions

  1. Rewrite the default as a simple quoted string, decimal, long, or boolean literal
  2. Cast/convert within the SQL body instead of relying on the default value
  3. Supply the value via the parameters dictionary at execution time

Example fix

// before
SET @Published = yes
// after
SET @Published = true
Defensive patterns

Strategy: validation

Validate before calling

// Only pass bool/string/decimal/long literals as defaults; verify at parse time
if (defaultValue is not (bool or string or decimal or long)) throw new ArgumentException("Default must be bool, string, decimal, or long");

Try / catch

try { result = parser.Parse(sql, parameters); } catch (InvalidOperationException ex) when (ex.Message.Contains("Unsupported default parameter")) { /* rewrite the query default */ }

Prevention

When it happens

Trigger: Declaring a default for a SQL query parameter using a literal type outside {bool, string, decimal, long} — e.g. SET @Date = 2024-01-01 (parsed as something other than a supported literal) or a non-literal expression.

Common situations: See trigger scenarios.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

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

            }

            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)