LiteDB icon indicating copy to clipboard operation
LiteDB copied to clipboard

[SUGGESTION] Include the field name in InvalidCastException

Open nabeelio opened this issue 3 years ago • 0 comments

This error:

System.InvalidCastException
Unable to cast object of type 'System.String' to type 'System.Int32'.

Trace:

System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Int32'.
  ?, in void lambda_method858(Closure, object, object)
  ?, in void BsonMapper.DeserializeObject(EntityMapper entity, object obj, BsonDocument value)
  ?, in object BsonMapper.Deserialize(Type type, BsonValue value)
  ?, in void BsonMapper.DeserializeObject(EntityMapper entity, object obj, BsonDocument value)
  ?, in object BsonMapper.Deserialize(Type type, BsonValue value)
  ?, in IEnumerable<T> LiteQueryable<T>.ToEnumerable()+(BsonDocument x) => { } [2]
  ?, in bool SelectEnumerableIterator<TSource, TResult>.MoveNext()
  ?, in TSource Enumerable.TryGetFirst<TSource>(IEnumerable<TSource> source, out bool found)
  ?, in TSource Enumerable.FirstOrDefault<TSource>(IEnumerable<TSource> source)
  ?, in T LiteCollection<T>.FindOne(Query query)
  ?, in T DatabaseInterface.GetFirstEntryFromCollection<T>(ILiteCollection<T> collection)
  ?, in Pirep PirepService.Load()
  ?, in async Task MainWindow.CheckForPirepLoadOrResume()
  ?, in async Task MainWindow.Bootstrap()

I though there used to be a custom exception with more details to trap - but as it is, it's close to impossible to debug - I have a class that has dozens of int fields, and it's getting data externally. Only see this when deserializing. But having the name of the field would go a long way to being able to debug this.

Thanks!

nabeelio avatar Jun 24 '22 15:06 nabeelio