Skip to content

SqlDataReader.GetFieldValueAsync throws InvalidCastException for nullable columns #33

@priyankatiwari08

Description

@priyankatiwari08

When reading a nullable int column with GetFieldValueAsync<int?>, an InvalidCastException is thrown for DBNull values. The synchronous GetFieldValue<int?> works correctly on the same column.

What happens

using var reader = await cmd.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
    var value = await reader.GetFieldValueAsync<int?>(0); // throws on DBNull rows
}

Expected: returns null for DBNull rows, same as the sync path.
Actual: InvalidCastException: Specified cast is not valid.

This is blocking us from migrating an async pipeline.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions