I am getting below error randomly from Dapper Repository Pattern. Strange thing is, I am getting this error randomly, in random APIs, for example, if API A is throwing this error, then in next second, it will work fine, without any error.
.Net Version: .Net 6.0
Tried below Dapper SDK version.
- 2.0.123
- 2.0.35
Error: Error parsing column 2 (MiddleName=94oMNxc/asdfghqwq== - String)
Code:
public List<T> GetTable<T>(string query, object parameters, CommandType type = CommandType.StoredProcedure)
{
ParameterValidator.ValidateString(query, nameof(query));
ParameterValidator.ValidateObject(parameters, nameof(parameters));
SqlMapper.AddTypeHandler(new StringTypeHandlers());
return Connection.Query<T>(query, parameters, null, true, CommandTimeout, type).ToList();
}
Stack Trace:
at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in /_/Dapper/SqlMapper.cs:line 3706
at Deserializee6048125-3c36-4442-915f-f3549b82d2e6(IDataReader )
at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in /_/Dapper/SqlMapper.cs:line 1113
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) in /_/Dapper/SqlMapper.cs:line 734
at billiyo.dapper.implementations.DapperRepository.GetTable[T](String query, Object parameters, CommandType type) in D:\XYZ\APIs\XYZ-api\XYZ.dapper\implementations\DapperRepository.cs:line 63
at billiyo.helpers.implementations.SharedHelpers.GetEmployeesAll(String TimiroCode) in D:\XYZ\APIs\XYZ-api\XYZ.helpers\implementations\SharedHelpers.cs:line 123
at XYZ.api.Controllers.SharedController.GetEmployeesAll(ISharedHelpers sharedHelpers) in D:\XYZ\APIs\XYZ-api\XYZ.api\Controllers\SharedController.cs:line 285
at lambda_method59(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
