本文介绍了Collection.Find(....)、Collection.FindAll() 都抛出异常,消息“值不能为空参数名称方法";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人物模型:

public class Person {公共 Int32 Id { 获取;放;}公共字符串名称 { 获取;放;}}

从数据库中查找人员:

public List找(){使用 (var db = new LiteDatabase(DatabasePathProvider.CacheLiteDbPath)){var col = db.GetCollection("Person");var list = col.FindOne(m => m.Name != null);退货清单;}}

在数据库上执行查找查询时,如代码所示,堆栈跟踪引发此异常:

 at System.Dynamic.Utils.ContractUtils.RequiresNotNull (System.Object value, System.String paramName) [0x00003] in :0在 System.Linq.Expressions.Expression.Call (System.Reflection.MethodInfo 方法, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1) [0x00000] 在 <1ea41f79845a40618089713a1d9403c在 LiteDB.BsonExpression.ParseSingleExpression (LiteDB.StringScanner s, System.Linq.Expressions.ParameterExpression root, System.Linq.Expressions.ParameterExpression current, System.Boolean isRoot) [0x0004c] 在 <a5ae904d7e214gt1da931e2076893在 LiteDB.BsonExpression.ParseExpression (LiteDB.StringScanner s, System.Linq.Expressions.ParameterExpression root, System.Linq.Expressions.ParameterExpression current, System.Boolean algorithmOnly) [0x00000] in <a5ae904d7e2141da931e206180317在 LiteDB.BsonExpression.Compile (LiteDB.StringScanner s, System.Boolean pathOnly, System.Boolean algorithmOnly) [0x00045] 在 <a5ae904d7e2141da931e206893177173>:0在 LiteDB.BsonExpression.Compile (System.String expression) [0x0003a] 在 <a5ae904d7e2141da931e206893177173>:0在 LiteDB.BsonExpression..ctor (System.String expression) [0x00010] 在 <a5ae904d7e2141da931e206893177173>:0在 LiteDB.Query.Run (LiteDB.CollectionPage col, LiteDB.IndexService indexer) [0x00055] 在 <a5ae904d7e2141da931e206893177173>:0在 LiteDB.LiteEngine+<Find>d__9.MoveNext () [0x000cd] 在 <a5ae904d7e2141da931e206893177173>:0在 LiteDB.LiteEngine+<Find>d__13.MoveNext () [0x001e4] 在 <a5ae904d7e2141da931e206893177173>:0在 LiteDB.LiteCollection`1+<Find>d__17[T].MoveNext() [0x000ba] 在 <a5ae904d7e2141da931e206893177173>:0在 System.Linq.Enumerable.TryGetFirst[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Boolean& found) [0x00045] 在 <1ea41f79845a40618089713a1d9403c4>:在 System.Linq.Enumerable.FirstOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] 源) [0x00000] 在 <1ea41f79845a40618089713a1d9403c4>:0在 LiteDB.LiteCollection`1[T].FindOne(System.Linq.Expressions.Expression`1[TDelegate] 谓词)[0x0000d] 在 <a5ae904d7e2141da931e206893177173>:0在 UandUST.Cache.Cache+d__0.MoveNext () [0x000a0] 在 C:\Users\iMentor\source\repos\ust\UandUSTAppCenterGit\UandUST\UandUST\Cache\Cache.cs:35
解决方案

您安装的 litedb 不正确:

https://github.com/mbdavid/LiteDB/issues/896

似乎缺少这些 litedb 依赖项:

System.Reflection (>= 4.3.0)System.Reflection.TypeExtensions (>= 4.3.0)

只需删除对 LiteDB 的旧引用并使用此 nuget 包安装它:

https://www.nuget.org/packages/LiteDB/>

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
解决方案

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/

这篇关于Collection.Find(....)、Collection.FindAll() 都抛出异常,消息“值不能为空参数名称方法";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 08:51