DapperLib / DapperLib/Dapper

"Value cannot be null" exception on query

Open
#714 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

When invoking the following code:

var cmdText = @"SELECT v.ID AS Id,
PROVIDER_NM AS ProviderName,
COST_INFO AS CostInfoHtml,
SUN_FROM_TIME AS SundayFromTime,
SUN_TO_TIME AS SundayToTime,
MON_FROM_TIME AS MondayFromTime,
MON_TO_TIME AS MondayToTime,
TUE_FROM_TIME AS TuesdayFromTime,
TUE_TO_TIME AS TuesdayToTime,
WED_FROM_TIME AS WednesdayFromTime,
WED_TO_TIME AS WednesdayToTime,
THU_FROM_TIME AS ThursdayFromTime,
THU_TO_TIME AS ThursdayToTime,
FRI_FROM_TIME AS FridayFromTime,
FRI_TO_TIME AS FridayToTime,
SAT_FROM_TIME AS SaturdayFromTime,
SAT_TO_TIME AS SaturdayToTime,
IS_TRANSIT_PROVIDER AS IsTransitProvider,
pp.phone_nbr AS PrimaryPhoneNumber
FROM v_provider v
LEFT OUTER JOIN provider_phone pp
    ON pp.provider_id = v.id
    AND pp.sort_order = 0
WHERE locale_cd = :localeCode
AND v.ID BETWEEN 223 and 800 -- for testing only";

IEnumerable<ProviderBase> results;

using (var conn = new OracleConnection(_connStr))
{
    results = conn.Query<ProviderBase>(cmdText, new { localeCode = "en" });
}

the following exception is raised:

System.ArgumentNullException was unhandled by user code
  HResult=-2147467261
  Message=Value cannot be null.
Parameter name: value
  ParamName=value
  Source=mscorlib
  StackTrace:
       at System.BitConverter.ToString(Byte[] value, Int32 startIndex, Int32 length)
       at OracleInternal.TTC.TTCLob.GetLobIdString(Byte[] lobLocator)
       at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
       at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
       at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
       at Dapper.SqlMapper.<QueryImpl>d__125`1.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType)
       at FindARide.Models.FindARideRepository.GetProviders(Search search) in D:\Projects\Find-A-Ride\src\FindARide\Models\FindARideRepository.cs:line 228
       at FindARide.Controllers.ProviderController.GetProviders(Double startingPointLon, Double startingPointLat, Double destinationLon, Double destinationLat, Int32[] needTypes, Int32[] scheduleTypes, Int32[] routeTypes, Int32[] riderTypes, Int32[] specialAccommodations, String ageRange, Boolean hasDriverLicense, String locale) in D:\Projects\Find-A-Ride\src\FindARide\Controllers\ProviderController.cs:line 55
       at lambda_method(Closure , Object , Object[] )
       at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionFilterAsync>d__28.MoveNext()
  InnerException: 

If I issue the query again, but instead of using the AND v.ID BETWEEN 0 and 800 predicate I use AND v.ID BETWEEN 0 and 400 or AND v.ID BETWEEN 400 and 800, the exception never occurs. For other predicates, such as AND v.ID BETWEEN 223 and 800, the exception occurs intermittently. I cannot narrow down to any particular offending row in the result set; rather there seems to be some strange interaction between rows depending perhaps the order they are returned by the database.

I'm using Dapper with ASP.Net Core and Oracle 11g. Happy to add detail as requested.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at FindARideRepository.cs line 228 and reproduce the query through Dapper's SqlMapper.Query using OracleConnection and Oracle 11g. Compare the full ID range with the split ranges and inspect the OracleDataReader stack shown in the report. Done means identifying the cause of the intermittent null-value exception and documenting a reliable reproduction or confirmed resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.