问题
Person Model:
public class Person {
public Int32 Id { get; set; }
public String Name { get; set; }
}
Find Person from DB:
public List<Person> find()
{
using (var db = new LiteDatabase(DatabasePathProvider.CacheLiteDbPath))
{
var col = db.GetCollection<Person>("Person");
var list = col.FindOne(m => m.Name != null);
return list;
}
}
On executing the find query on the database as shown in the code, This exception is thrown with stack trace:
at System.Dynamic.Utils.ContractUtils.RequiresNotNull (System.Object value, System.String paramName) [0x00003] in <1ea41f79845a40618089713a1d9403c4>:0
at System.Linq.Expressions.Expression.Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1) [0x00000] in <1ea41f79845a40618089713a1d9403c4>:0
at LiteDB.BsonExpression.ParseSingleExpression (LiteDB.StringScanner s, System.Linq.Expressions.ParameterExpression root, System.Linq.Expressions.ParameterExpression current, System.Boolean isRoot) [0x0004c] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.BsonExpression.ParseExpression (LiteDB.StringScanner s, System.Linq.Expressions.ParameterExpression root, System.Linq.Expressions.ParameterExpression current, System.Boolean arithmeticOnly) [0x00000] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.BsonExpression.Compile (LiteDB.StringScanner s, System.Boolean pathOnly, System.Boolean arithmeticOnly) [0x00045] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.BsonExpression.Compile (System.String expression) [0x0003a] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.BsonExpression..ctor (System.String expression) [0x00010] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.Query.Run (LiteDB.CollectionPage col, LiteDB.IndexService indexer) [0x00055] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.LiteEngine+<Find>d__9.MoveNext () [0x000cd] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.LiteEngine+<Find>d__13.MoveNext () [0x001e4] in <a5ae904d7e2141da931e206893177173>:0
at LiteDB.LiteCollection`1+<Find>d__17[T].MoveNext () [0x000ba] in <a5ae904d7e2141da931e206893177173>:0
at System.Linq.Enumerable.TryGetFirst[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Boolean& found) [0x00045] in <1ea41f79845a40618089713a1d9403c4>:0
at System.Linq.Enumerable.FirstOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00000] in <1ea41f79845a40618089713a1d9403c4>:0
at LiteDB.LiteCollection`1[T].FindOne (System.Linq.Expressions.Expression`1[TDelegate] predicate) [0x0000d] in <a5ae904d7e2141da931e206893177173>:0
at UandUST.Cache.Cache+<Find>d__0.MoveNext () [0x000a0] in C:\Users\iMentor\source\repos\ust\UandUSTAppCenterGit\UandUST\UandUST\Cache\Cache.cs:35
回答1:
You have unproperly installed litedb:
https://github.com/mbdavid/LiteDB/issues/896
It seems these litedb dependencies are missing:
System.Reflection (>= 4.3.0)
System.Reflection.TypeExtensions (>= 4.3.0)
Just remove the old references to LiteDB and install it with this nuget package:
https://www.nuget.org/packages/LiteDB/
来源:https://stackoverflow.com/questions/57570249/collection-find-collection-findall-all-throwing-exception-with-message