部署到使用Unity 2019.4.12f1开发的ARM设备时LiteDB异常

问题描述

我试图在Unity 2019中使用针对ARM设备的LiteDB(net45,V5.0.9)。 sample code(文档中提供)可以执行CRUD操作,但在Unity编辑器中工作正常,但是在设备中却遇到此异常:

System.NotSupportedException: Invalid BsonExpression when converted from Linq expression: x => x.Name - $.Name ---> System.TypeInitializationException: The type initializer for 'LiteDB.BsonExpression' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: method
at System.Dynamic.Utils.ContractUtils.RequiresNotNull (System.Object value,System.String paramName) [0x00000] in <00000000000000000000000000000000>:0 
  at System.Linq.Expressions.Expression.Call (System.Reflection.MethodInfo method,System.Linq.Expressions.Expression arg0,System.Linq.Expressions.Expression arg1) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.BsonExpressionParser.TryParsePath (LiteDB.Tokenizer tokenizer,LiteDB.ExpressionContext context,LiteDB.BsonDocument parameters,LiteDB.DocumentScope scope) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.BsonExpressionParser.ParseSingleExpression (LiteDB.Tokenizer tokenizer,LiteDB.DocumentScope scope) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.BsonExpressionParser.ParseFullExpression (LiteDB.Tokenizer tokenizer,LiteDB.DocumentScope scope) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.BsonExpression.Create (System.String expression,LiteDB.BsonDocument parameters) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.BsonExpression.Create (System.String expression) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.BsonExpression..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.LinqExpressionVisitor.Resolve (System.Boolean predicate) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.BsonMapper.GetExpression[T,K] (System.Linq.Expressions.Expression1[TDelegate] predicate) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.LiteCollection1[T].GetIndexExpression[K] (System.Linq.Expressions.Expression1[TDelegate] keySelector) [0x00000] in <00000000000000000000000000000000>:0 
  at LiteDB.LiteCollection1[T].EnsureIndex[K] (System.Linq.Expressions.Expression1[TDelegate] keySelector,System.Boolean unique) [0x00000] in <00000000000000000000000000000000>:0 

我进行了一次谷歌搜索,发现了一个关于this的堆栈溢出问题,其中一个回答指出这可能是由于缺少依赖项所致。但是,我使用的是.NETFramework 4.5 DLL,根据NuGet page,它没有任何依赖性。

有人可以帮我吗?

编辑:

这是我使用的示例代码:

// Create your POCO class
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public string[] Phones { get; set; }
    public bool IsActive { get; set; }
}

// Open database (or create if doesn't exist)
using(var db = new LiteDatabase(@"MyData.db"))
{
    // Get customer collection
    var col = db.GetCollection<Customer>("customers");

    // Create your new customer instance
    var customer = new Customer
    { 
        Name = "John Doe",Phones = new string[] { "8000-0000","9000-0000" },Age = 39,IsActive = true
    };

    // Create unique index in Name field
    col.EnsureIndex(x => x.Name,true);

    // Insert new customer document (Id will be auto-incremented)
    col.Insert(customer);

    // Update a document inside a collection
    customer.Name = "Joana Doe";

    col.Update(customer);

    // Use LINQ to query documents (with no index)
    var results = col.Find(x => x.Age > 20);
}

问题可能是因为在IL2CPP后端上运行吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)