On random occasions, users of our application are receiving this invalid cast exception The expected type was 'System.Int64' but the actual value was of type 'System.String'. This is not reproducible by us and it occurs on an identity (DataGrid.Id) field of our DataGrid model. The type in the database is bigint
and the type in our model is long
.
This seems to have started to occur after we started using ToListAsync
instead of ToList
on the entity.
public async Task<IEnumerable<TEntity>> GetAllAsync()
{
return await _entitySet.ToListAsync();
}
I am not sure what is going on with these random requests throwing errors. I can provide a full stack trace if necessary, but the stack trace leads me to that line where it's throwing the exception, and it appears the data types match. This is usually a very random error and occurs once or twice every couple days. Can anyone suggest what may be occurring here?