praeclarum / sqlite-net

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

SQLite in iOS with Maui crashes when the app is published on the store #1227

Open erossini opened 5 months ago

erossini commented 5 months ago

In my NET8 MAUI application, I use SQLite and here are the packages I added to the project.

<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.6" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.8" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.8" />

The application reads the database quite often. In debug, the application runs normally without errors. When I published the application on the Apple store, when the app reads the database, the application crashed immediately. I can see the error in the AppCenter

SIGABRT: Attempting to JIT compile method '(wrapper delegate-invoke) void System.Action`2<LanguageInUse.Domain.Dictionary, System.DateTime>:invoke_callvirt_void_T1_T2 (LanguageInUse.Domain.Dictionary,System.DateTime)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

The full error is this one

SQLite.FastColumnSetter.<>c__DisplayClass2_0`2[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.DateTime, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<CreateTypedSetterDelegate>b__0(Object o, sqlite3_stmt stmt, Int32 i)
SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__12`1[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
System.Collections.Generic.List`1[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]..ctor(IEnumerable`1 )
System.Linq.Enumerable.ToList[Dictionary](IEnumerable`1 )
SQLite.SQLiteCommand.ExecuteQuery[Dictionary]()
SQLite.TableQuery`1[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ToList()
SQLite.AsyncTableQuery`1[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<ToListAsync>b__11_0(SQLiteConnectionWithLock conn)
SQLite.AsyncTableQuery`1.<>c__DisplayClass2_0`1[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Collections.Generic.List`1[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<ReadAsync>b__0()
System.Threading.Tasks.Task`1[[System.Collections.Generic.List`1[[LanguageInUse.Domain.Dictionary, LanguageInUse, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
System.Threading.Tasks.Task.<>c.<.cctor>b__281_0(Object obj)
System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object )
System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object )
System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& , Thread )
LanguageInUse.Persistence.LIUDatabase.GetDictionariesForSearchAsync(String username, String search)
LanguageInUse.ViewModels.DictionaryListViewModel.<Init>b__13_0(Object s, PopupOpenedEventArgs e)
System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
Foundation.NSAsyncSynchronizationContextDispatcher.Apply()
ObjCRuntime.Runtime.ThrowException(IntPtr )
UIKit.UIApplication.UIApplicationMain(Int32 , String[] , IntPtr , IntPtr )
UIKit.UIApplication.Main(String[] , Type , Type )
LanguageInUse.Program.Main(String[] args)

I tried in debug and release on my real devices and the application is working. I saw on GitHub this quite similar bug but it is 2 years old. In this post, they recommend downgrading the SQLite version - 2 years ago - or building with these settings.

enter image description here

Also, I saw this other issue always on GitHub that is more recent. They said to use in Release for iOS this settings

<UseInterpreter>true</UseInterpreter>
<MtouchInterpreter>-all</MtouchInterpreter>

I don't want to send more updates to the Apple Store with a broken app. Do you face the same issue? How can I fix the problem?

onurhazar commented 4 months ago

@erossini any news after adding two properties? did you solve the issue? we are facing the same error.

SergTomcat commented 1 month ago

@erossini I'm still on 1.7.335 solely because of that issue. Does enabling interpreter really helps?

And what is current status of that problem?

it11111111 commented 1 month ago

Also facing the same issue. Ive tried enabling the interpreter but it does not seem to help