dotnet/orleans · error · InvalidOperationException

Expected a single column

Error message

Expected a single column

What it means

Thrown by DbStoredQueries.Converters.GetSingleBooleanValue when the IDataRecord has a FieldCount other than 1. This helper expects a query that returns exactly one column holding a boolean-ish value (used to confirm inserts/updates succeeded). A multi-column (or zero-column) result indicates the query text is wrong for its intended use.

Source

Thrown at src/AdoNet/Shared/Storage/DbStoredQueries.cs:288

            internal static Uri GetGatewayUri(IDataRecord record)
            {
                return GetSiloAddress(record, nameof(Columns.ProxyPort)).ToGatewayUri();
            }

            private static SiloAddress GetSiloAddress(IDataRecord record, string portName)
            {
                //Use the GetInt32 method instead of the generic GetValue<TValue> version to retrieve the value from the data record
                //GetValue<int> causes an InvalidCastException with orcale data provider. See https://github.com/dotnet/orleans/issues/3561
                int port = record.GetInt32(portName);
                int generation = record.GetInt32(nameof(Columns.Generation));
                string address = record.GetValue<string>(nameof(Columns.Address));
                var siloAddress = SiloAddress.New(IPAddress.Parse(address), port, generation);
                return siloAddress;
            }

            internal static bool GetSingleBooleanValue(IDataRecord record)
            {
                if (record.FieldCount != 1) throw new InvalidOperationException("Expected a single column");
                return Convert.ToBoolean(record.GetValue(0));
            }
        }

        internal class Columns
        {
            private readonly IDbCommand command;

            internal Columns(IDbCommand cmd)
            {
                command = cmd;

            }

            private void Add<T>(string paramName, T paramValue, DbType? dbType = null)
            {
                command.AddParameter(paramName, paramValue, dbType: dbType);
            }

View on GitHub (pinned to fca799fa70)

Solutions

  1. Correct the offending OrleansQuery QueryText so it returns exactly one column convertible to Boolean (e.g. 'SELECT CAST(@@ROWCOUNT AS BIT)' or 'SELECT 1').
  2. Re-apply the canonical Orleans setup script for your version to restore the intended single-column query.
  3. Inspect the OrleansQuery table for the relevant key and fix the QueryText.

Example fix

-- before (returns two columns)
UPDATE ... ; SELECT 1, @@ROWCOUNT;

-- after (single boolean column)
UPDATE ... ; SELECT CAST(@@ROWCOUNT AS BIT);
Defensive patterns

Strategy: validation

Validate before calling

// For queries intended to return a single boolean, assert shape before reading.
if (record.FieldCount != 1)
    throw new InvalidOperationException($"Query must return exactly one column, got {record.FieldCount}.");

Try / catch

try { var ok = DbStoredQueries.Converters.GetSingleBooleanValue(record); }
catch (InvalidOperationException ex) when (ex.Message.Contains("single column")) { /* fix the OrleansQuery text */ throw; }

Prevention

When it happens

Trigger: Calling GetSingleBooleanValue(record) on a record whose FieldCount != 1. Reached when an OrleansQuery entry used for a single-boolean check (e.g. an INSERT/UPDATE confirmation query) was authored to SELECT more than one column, or no columns at all.

Common situations: A custom or hand-edited OrleansQuery row returns extra columns (e.g. SELECT * instead of SELECT 1); schema scripts from a mismatched version; a query that returns a row count column alongside the boolean.

Related errors


AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13). Data as JSON: /api/errors/53679fecdd130b4a. Report an issue: GitHub.