[CSHARP-1696] Object must implement IConvertible Created: 27/Jun/16 Updated: 02/Feb/22 Resolved: 02/Feb/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | 2.2.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Marko Hrovatic | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | triaged | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
windows |
||
| Epic Link: | CSHARP-3615 |
| Description |
|
With this query handler
the driver would throw an exception
Only and only when the collection in question would be empty. |
| Comments |
| Comment by James Kovacs [ 02/Feb/22 ] |
|
We were not able to reproduce this issue with recent versions of the driver. If you are still observing this issue, please re-open this ticket with any updated information that you can provide. |
| Comment by Marko Hrovatic [ 27/Jun/16 ] |
|
seriously, cannnot edit the Description? Ok here goes With this query handler public class AppointmentsFromDateToDateQuery : IQuery<IEnumerable<Appointment>> public DateTimeOffset To { get; set; } } public class AppointmentsFromDateToDateQueryHandler : IQueryHandlerAsync<AppointmentsFromDateToDateQuery, IEnumerable<Appointment>> public AppointmentsFromDateToDateQueryHandler(IMongoDatabase db) { _db = db; }public async Task<IEnumerable<Appointment>> HandleAsync(AppointmentsFromDateToDateQuery query) { return await _db.GetCollection<Appointment>(typeof(Appointment).Name) .Find(a => a.Starts >= query.From && a.Ends <= query.To) .SortBy(a => a.Starts) .ToListAsync(); }and this usage var query = new AppointmentsFromDateToDateQuery() { From = date.Value, To = date.Value.AddDays(1) }; the driver would throw an exception [InvalidCastException: Object must implement IConvertible.] Only and only when the collection in question would be empty. The problem actually lies in the return type of IEnumerable which the driver apparently has a trouble of instantiating. This is something that normally works with Entity Framework (returning empty IEnumerables). |