tmsmith / Dapper-Extensions

Dapper Extensions is a small library that complements Dapper by adding basic CRUD operations (Get, Insert, Update, Delete) for your POCOs. For more advanced querying scenarios, Dapper Extensions provides a predicate system. The goal of this library is to keep your POCOs pure by not requiring any attributes or base class inheritance.
1.79k stars 584 forks source link

Async methods are throwing exceptions because Task.FromResult does not specify type <T> #317

Open efron-cem opened 1 year ago

efron-cem commented 1 year ago

The async CRUD methods like GetAsync are sometimes throwing exceptions like below

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The type arguments for method 'System.Threading.Tasks.Task.FromResult<TResult>(TResult)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
   at CallSite.Target(Closure , CallSite , Type , Object )
   at DapperExtensions.DapperAsyncImplementor.GetAsync[T](IDbConnection connection, Object id, IDbTransaction transaction, Nullable`1 commandTimeout, Boolean buffered, IList`1 colsToSelect, IList`1 includedProperties)
   at CallSite.Target(Closure , CallSite , Object )
   at DapperExtensions.DapperAsyncExtensions.GetAsync[T](IDbConnection connection, Object id, IDbTransaction transaction, Nullable`1 commandTimeout, Boolean buffered)
   at Repository.GetAsync(SqlConnection connection, Guid blueprintId) in myfile.cs:line -1

I assume this happens when there is nothing in the database, and the async method's Task.FromResult have trouble with returning it because it doesn't know what type null is. The type just needs to be added to the Task.FromResult call, it should be a very quick and easy fix.

The methods are in DapperAsyncImplementor.cs

Please and Thanks!