praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.06k stars 1.42k forks source link

1.8.0-beta - System.ArgumentException: method arguments are incompatible #1048

Closed tranb3r closed 3 years ago

tranb3r commented 3 years ago

There is an exception when using the new version sqlite-net-pcl 1.8.0-beta with SqliteNetExtensions

[Error] Exception catched !!!System.ArgumentException: method arguments are incompatible
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) [0x002e3] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System/Delegate.cs:281 
  at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System/Delegate.cs:296 
  at SQLite.FastColumnSetter.CreateNullableTypedSetterDelegate[ObjectType,ColumnMemberType] (SQLite.TableMapping+Column column, System.Func`3[T1,T2,TResult] getColumnValue) [0x00077] in <a9edccd8a27f41fdaae16acd8ec0ca8e>:0 
  at SQLite.FastColumnSetter.GetFastSetter[T] (SQLite.SQLiteConnection conn, SQLite.TableMapping+Column column) [0x000a0] in <a9edccd8a27f41fdaae16acd8ec0ca8e>:0 
  at SQLite.SQLiteCommand+<ExecuteDeferredQuery>d__12`1[T].MoveNext () [0x000d1] in <a9edccd8a27f41fdaae16acd8ec0ca8e>:0 
  at System.Collections.Generic.List`1[T].AddEnumerable (System.Collections.Generic.IEnumerable`1[T] enumerable) [0x00059] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:1108 
  at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x00062] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:87 
  at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0000e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:30 
  at SQLite.SQLiteCommand.ExecuteQuery[T] (SQLite.TableMapping map) [0x00007] in <a9edccd8a27f41fdaae16acd8ec0ca8e>:0 
  at SQLite.SQLiteConnection.Query (SQLite.TableMapping map, System.String query, System.Object[] args) [0x00008] in <a9edccd8a27f41fdaae16acd8ec0ca8e>:0 
  at SQLiteNetExtensions.Extensions.ReadOperations.GetManyToOneChildren[T] (SQLite.SQLiteConnection conn, System.Collections.Generic.IList`1[T] elements, System.Reflection.PropertyInfo relationshipProperty, System.Boolean recursive, System.Collections.Generic.Dictionary`2[TKey,TValue] objectCache) [0x00159] in D:\Dev\Zitch\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:358 
  at SQLiteNetExtensions.Extensions.ReadOperations.GetChildRecursive (SQLite.SQLiteConnection conn, System.Object element, System.Reflection.PropertyInfo relationshipProperty, System.Boolean recursive, System.Collections.Generic.Dictionary`2[TKey,TValue] objectCache) [0x00044] in D:\Dev\Zitch\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:190 
  at SQLiteNetExtensions.Extensions.ReadOperations.GetChildrenRecursive (SQLite.SQLiteConnection conn, System.Object element, System.Boolean onlyCascadeChildren, System.Boolean recursive, System.Collections.Generic.Dictionary`2[TKey,TValue] objectCache) [0x0003a] in D:\Dev\Zitch\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:169 
  at SQLiteNetExtensions.Extensions.ReadOperations.GetChildren[T] (SQLite.SQLiteConnection conn, T element, System.Boolean recursive) [0x00000] in D:\Dev\Zitch\sqlite-net-extensions\SQLiteNetExtensions\Extensions\ReadOperations.cs:110 
  at SQLiteNetExtensionsAsync.Extensions.ReadOperations+<>c__DisplayClass3_0`1[T].<GetChildrenAsync>b__0 () [0x00029] in D:\Dev\Zitch\sqlite-net-extensions\SQLiteNetExtensionsAsync\Extensions\ReadOperations.cs:123 
  at System.Threading.Tasks.Task.InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2476 
  at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319 

This issue has been introduced in 1.8.0-beta with PR https://github.com/praeclarum/sqlite-net/pull/902 (Fast Column Setters)

I've created a simple repro project, with 2 applications:

With sqlite-net-pcl 1.8.0-beta, there is an exception on both environments:

No error with 1.7.335.

The code for the test is in TestClass.cs in the shared lib (TestSqliteNet). It uses sqlite-net-pcl and SQLiteNetExtensions ; no need for sqlcipher nor async api.

TestSqliteNet.zip

tranb3r commented 3 years ago

@praeclarum Could you please take a look at this regression before you release the final 1.8.0 ? Thanks !

inforithmics commented 3 years ago

Minimal reproduction sample:

var db = new SQLiteConnection(dbPath);
db.CreateTable<ClassB>();
var b = new ClassB();
db.Insert(b);

var test = db.CreateCommand("select * from ClassB")
                .ExecuteDeferredQuery<object>(new TableMapping(typeof(ClassB))).ToList();
praeclarum commented 3 years ago

Thank you @tranb3r for this fix. This is an interesting one... the nullable design strikes again.

tranb3r commented 3 years ago

Thanks @inforithmics for the fix !!