dotnet/efcore · error · ArgumentOutOfRangeException
A FromSqlExpression has an invalid arguments expression type
Error message
A FromSqlExpression has an invalid arguments expression type '{expressionType}' or value type '{valueType}'. What it means
Thrown by QuerySqlGenerator.VisitFromSql when the FromSqlExpression's Arguments property is not a recognized type. The generator expects Arguments to be either a ParameterExpression (representing a parameterized SQL string) or a ConstantExpression containing a string array or object array of parameter values. Any other expression type triggers this ArgumentOutOfRangeException.
Source
Thrown at src/EFCore.Relational/Query/QuerySqlGenerator.cs:510
for (var i = 0; i < constantValues.Length; i++)
{
switch (constantValues[i])
{
case RawRelationalParameter rawRelationalParameter:
substitutions[i] = _sqlGenerationHelper.GenerateParameterNamePlaceholder(rawRelationalParameter.InvariantName);
_relationalCommandBuilder.AddParameter(rawRelationalParameter);
break;
case SqlConstantExpression sqlConstantExpression:
substitutions[i] = sqlConstantExpression.TypeMapping!.GenerateSqlLiteral(sqlConstantExpression.Value);
break;
}
}
break;
}
default:
throw new ArgumentOutOfRangeException(
nameof(fromSqlExpression),
fromSqlExpression.Arguments,
RelationalStrings.InvalidFromSqlArguments(
fromSqlExpression.Arguments.GetType(),
fromSqlExpression.Arguments is ConstantExpression constantExpression
? constantExpression.Value?.GetType()
: null));
}
// ReSharper disable once CoVariantArrayConversion
// InvariantCulture not needed since substitutions are all strings
sql = string.Format(sql, substitutions);
_relationalCommandBuilder.AppendLines(sql);
}
/// <summary>
/// Generates SQL for a user-provided SQL query.View on GitHub (pinned to 3a2006ef56)
Solutions
- Verify your FromSqlRaw/FromSqlInterpolated call uses standard parameter patterns (string SQL + params object[] for raw, FormattableString for interpolated).
- If using a third-party provider, report the issue — it may be constructing FromSqlExpression incorrectly.
- File a bug at https://github.com/dotnet/efcore with the FromSql query and full stack trace.
- As a workaround, switch between FromSqlRaw and FromSqlInterpolated to see if one avoids the issue.
Example fix
// before — ensure standard API usage (this error is typically internal)
var blogs = context.Blogs.FromSqlRaw("SELECT * FROM Blogs WHERE Id = {0}", id);
// after — use interpolated form if raw triggers the issue
var blogs = context.Blogs.FromSqlInterpolated($"SELECT * FROM Blogs WHERE Id = {id}"); Defensive patterns
Strategy: try-catch
Try / catch
try
{
var result = await context.Blogs.FromSqlRaw("SELECT * FROM Blogs").ToListAsync();
}
catch (ArgumentOutOfRangeException ex) when (ex.Message.Contains("FromSqlExpression has an invalid arguments"))
{
logger.LogError(ex, "Invalid FromSql arguments — internal or provider bug");
// Try FromSqlInterpolated as an alternative
var result = await context.Blogs.FromSqlInterpolated($"SELECT * FROM Blogs").ToListAsync();
} Prevention
- Use standard FromSqlRaw and FromSqlInterpolated APIs — never construct FromSqlExpression manually.
- Ensure parameter values are passed as params object[] or via FormattableString, not as expression trees.
- Report internal FromSql argument errors to the EF Core team or provider maintainer.
- Keep EF Core and provider packages updated to pick up bug fixes.
When it happens
Trigger: Internal pipeline constructs a FromSqlExpression with an Arguments value that is not a string ConstantExpression, a string array ConstantExpression, or a ParameterExpression. This is an internal invariant violation — FromSqlRaw and FromSqlInterpolated always produce valid argument shapes, so this throw indicates either a bug in EF Core or a misuse of the internal FromSqlExpression constructor.
Common situations: An EF Core internal bug where FromSqlExpression is constructed with invalid arguments during query compilation. A third-party provider or extension that manually constructs FromSqlExpression instances incorrectly. Very rare; standard FromSqlRaw/FromSqlInterpolated APIs always produce valid argument shapes.
Related errors
- Unhandled expression '{expression}' of type '{expressionType
- The operation '{operation}' contains a select expression fea
- Unhandled expression '{expression}' of type '{expressionType
- Cosmos SQL does not allow Offset without Limit. Consider spe
- A FromSqlExpression has an invalid arguments expression type
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/cff23031304cfab1.
Report an issue: GitHub.