sqlite-net
sqlite-net copied to clipboard
Not working on iOS after 1.8.116 - Attempting to JIT compile method '(wrapper delegate-invoke)
Steps to reproduce:
- Create Xamarin.iOS application
- Create SQLAsyncConnection
- Access Entity via Table<T>().FindOneAsync
Error:
Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_UserInfo_Guid (Skandy.Mobile.Domain.UserInfo,System.Guid)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information. ; Version: 1.6.408. iOS: 8C36CE78-3988-40D7-9CDB-54BF1677E694
at SQLite.FastColumnSetter+<>c__DisplayClass2_02[ObjectType,ColumnMemberType].<CreateTypedSetterDelegate>b__0 (System.Object o, SQLitePCL.sqlite3_stmt stmt, System.Int32 i) <0x1059bd710 + 0x00187> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at SQLite.SQLiteCommand+<ExecuteDeferredQuery>d__12
1[T].MoveNext () <0x1059e7ec4 + 0x0031f> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at System.Collections.Generic.List1[T].AddEnumerable (System.Collections.Generic.IEnumerable
1[T] enumerable) <0x104f40934 + 0x000b3> in <da8885cdf78b449d96de00cdb9d47225#a6464d95a03c7bacba393abaab79514c>:0 at System.Collections.Generic.List1[T]..ctor (System.Collections.Generic.IEnumerable
1[T] collection) <0x104f3e330 + 0x00193> in <da8885cdf78b449d96de00cdb9d47225#a6464d95a03c7bacba393abaab79514c>:0 at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable1[T] source) <0x105652e54 + 0x00093> in <26bd496943a145e18f2cd8379c502c52#a6464d95a03c7bacba393abaab79514c>:0 at SQLite.SQLiteCommand.ExecuteQuery[T] () <0x1059e64b4 + 0x00073> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at SQLite.TableQuery
1[T].ToList () <0x1059efeb0 + 0x00063> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at SQLite.TableQuery1[T].FirstOrDefault () <0x1059f0084 + 0x0002b> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at SQLite.SQLiteConnection.Find[T] (System.Linq.Expressions.Expression
1[TDelegate] predicate) <0x1059dd4a4 + 0x00047> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at SQLite.SQLiteAsyncConnection+<>c__DisplayClass70_01[T].<FindAsync>b__0 (SQLite.SQLiteConnectionWithLock conn) <0x1059f5a88 + 0x00047> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at SQLite.SQLiteAsyncConnection+<>c__DisplayClass32_0
1[T].<ReadAsync>b__0 () <0x1059f4b14 + 0x0006f> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at System.Threading.Tasks.Task`1[TResult].InnerInvoke () <0x104e432a8 + 0x000bb> in <da8885cdf78b449d96de00cdb9d47225#a6464d95a03c7bacba393abaab79514c>:0 at System.Threading.Tasks.Task.Execute () <0x104e4796c + 0x00023> in <da8885cdf78b449d96de00cdb9d47225#a6464d95a03c7bacba393abaab79514c>:0 ---
We experience this issue too using FirstOrDefaultAsync:
await Database.Table<T>().FirstOrDefaultAsync()
Same Problem here with GetAllWithChildren():
same problem with SQLiteConnection.Query<T>()
stack trace for me: Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_Profile_string (WibciLabs.Remotime.Models.Profile,string)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
at SQLite.FastColumnSetter+<>c__DisplayClass2_02[ObjectType,ColumnMemberType].<CreateTypedSetterDelegate>b__0 (System.Object o, SQLitePCL.sqlite3_stmt stmt, System.Int32 i) <0x103e9be64 + 0x0009c> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at SQLite.SQLiteCommand+<ExecuteDeferredQuery>d__12
1[T].MoveNext () <0x103e9843c + 0x0031b> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0
at System.Collections.Generic.List1[T].AddEnumerable (System.Collections.Generic.IEnumerable
1[T] enumerable) <0x100f2d75c + 0x000b3> in <218435b0f6654ac1ab0cdd176f26b9bd#a4fcafd7c547d2e8197af938ed6ad9c4>:0
at System.Collections.Generic.List1[T]..ctor (System.Collections.Generic.IEnumerable
1[T] collection) <0x100f2a258 + 0x0018f> in <218435b0f6654ac1ab0cdd176f26b9bd#a4fcafd7c547d2e8197af938ed6ad9c4>:0
at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable1[T] source) <0x1015146c0 + 0x0008f> in <8e6764529e4c4797b1ffdaa92a5f1151#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at SQLite.SQLiteCommand.ExecuteQuery[T] () <0x103e96a80 + 0x0006f> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at SQLite.SQLiteConnection.Query[T] (System.String query, System.Object[] args) <0x103e8d78c + 0x00033> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at SQLite.SQLiteConnection.Find[T] (System.Object pk) <0x103e8dbec + 0x0008f> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at SQLite.SQLiteAsyncConnection+<>c__DisplayClass68_0
1[T].<FindAsync>b__0 (SQLite.SQLiteConnectionWithLock conn) <0x103ea5b20 + 0x00043> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0
at SQLite.SQLiteAsyncConnection+<>c__DisplayClass32_01[T].<ReadAsync>b__0 () <0x103ea4d14 + 0x0006b> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at System.Threading.Tasks.Task
1[TResult].InnerInvoke () <0x100e1c1a4 + 0x000b7> in <218435b0f6654ac1ab0cdd176f26b9bd#a4fcafd7c547d2e8197af938ed6ad9c4>:0
at System.Threading.Tasks.Task.Execute () <0x100e21248 + 0x0001f> in <218435b0f6654ac1ab0cdd176f26b9bd#a4fcafd7c547d2e8197af938ed6ad9c4>:0
--- End of stack trace from previous location where exception was thrown ---
Same error here. 1.7.335 works but 1.8.116 fails
{System.ExecutionEngineException: Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_OilCompanyModel_string (RPT.Model.OilCompanyModel,string)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
at SQLite.FastColumnSetter+<>c__DisplayClass2_0`2[ObjectType,ColumnMemberType].<CreateTypedSetterDelegate>b__0 (System.Object o, SQLitePCL.sqlite3_stmt stmt, System.Int32 i) [0x00023] in <01c96d411fe34bd5940c99a56515582b>:0
at SQLite.SQLiteCommand+<ExecuteDeferredQuery>d__12`1[T].MoveNext () [0x00218] in <01c96d411fe34bd5940c99a56515582b>:0
at System.Collections.Generic.List`1[T].AddEnumerable (System.Collections.Generic.IEnumerable`1[T] enumerable) [0x00059] in <218435b0f6654ac1ab0cdd176f26b9bd>:0
at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x00062] in <218435b0f6654ac1ab0cdd176f26b9bd>:0
at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00018] in <8e6764529e4c4797b1ffdaa92a5f1151>:0
at SQLite.SQLiteCommand.ExecuteQuery[T] () [0x0001c] in <01c96d411fe34bd5940c99a56515582b>:0
at SQLite.SQLiteConnection.Query[T] (System.String query, System.Object[] args) [0x00008] in <01c96d411fe34bd5940c99a56515582b>:0
at SQLite.SQLiteAsyncConnection+<>c__DisplayClass83_0`1[T].<QueryAsync>b__0 (SQLite.SQLiteConnectionWithLock conn) [0x00000] in <01c96d411fe34bd5940c99a56515582b>:0
at SQLite.SQLiteAsyncConnection+<>c__DisplayClass32_0`1[T].<ReadAsync>b__0 () [0x00013] in <01c96d411fe34bd5940c99a56515582b>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <218435b0f6654ac1ab0cdd176f26b9bd>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
--- End of stack trace from previous location where exception was thrown ---
I'm having the same issue as above, I've tried, .Table<T>().Where(x => x...) and .Query<T>("query"), same issue, also with using 'ugly' I thought it might solve the issue, but still getting the same issue
There has been no response on this so I'll share my diagnosis:
FastColumnSetter was added 2 years ago in the code.
2 months ago PR #1059 was committed to the codebase.
In that PR a line was added to use MakeGenericMethod.
This is fine for anywhere that JIT is allowed, but on iOS if you have Link All Assemblies set (Release Mode) then it cannot work because it needs to create some code for the generics in question. This is not allowed in AOT mode on iOS.
https://stackoverflow.com/questions/24588090/makegenericmethod-makegenerictype-on-xamarin-ios
pull request with workaround
https://github.com/praeclarum/sqlite-net/pull/1064
I think you're spot on @paul-kiar, MakeGenericMethod
is basically guaranteed to fail on iDevices (unfortunately it works fine on simulators, which is probably why this is always caught late). Until now I was under the impression that the fast setters would work in this case because they were limited to hard coded simple types, but it seems there's still something devious going on that makes MakeGenericMethod
necessary. Think I'll have to downgrade for now.
I don't think that this is the problem because the MakeGeneric fixed this case
... .ExecuteDeferredQuery<object>(new TableMapping(typeof(ClassB))).ToList();
where object was added as the Type to fill.
This carshed with the Delegates because it tried to set properties on the object type which cannot work.
Like this.
object a = new object();
a.test = "test";
Besides The Version before already had this Compilation Bug. The workaround would be to AOT Compile with enabled Interpreter but this doesn't work because of another Bug.
https://github.com/mono/mono/issues/20417
Which seems not been merged yet into the release mono runtime.
I think the real solution for fixing this would be to write a Source Generator that uses the interface that I have added in this pull request. Then It will be even faster and AOT safe.
https://github.com/praeclarum/sqlite-net/pull/1064
It may not work for everyone, but I downgraded to 1.7.335 and my queries are working again.
It may not work for everyone, but I downgraded to 1.7.335 and my queries are working again.
This worked for me too.
I landed here after almost going insane trying to figure out why our app was failing at runtime, since it works fine in debug mode on a simulator. Being very grateful for all the work that has gone into this project already, I hope @praeclarum finds the time to update this library or incorporate the already existing PR since this is the de-facto standard for local storage on mobile devices (Xamarin developer here), and I would assume a lot of developers are affected.
Best regards & Thanks
Also facing this issue after updating to 1.8.116. Downgraded back to 1.7.335 as a temporary workaround. If it helps, here is my stack trace:
Attempting to JIT compile method '(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_Media_Guid (..,System.Guid)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
at SQLite.FastColumnSetter+<>c__DisplayClass2_0`2[ObjectType,ColumnMemberType].<CreateTypedSetterDelegate>b__0 (System.Object o, SQLitePCL.sqlite3_stmt stmt, System.Int32 i) [0x00023] in <9945edc4c42e4621a31b5582964d5150>:0
at SQLite.SQLiteCommand+<ExecuteDeferredQuery>d__12`1[T].MoveNext () [0x00218] in <9945edc4c42e4621a31b5582964d5150>:0
at System.Collections.Generic.List`1[T].AddEnumerable (System.Collections.Generic.IEnumerable`1[T] enumerable) [0x00059] in <25bf495f7d6b4944aa395b3ab5293479>:0
at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x00062] in <25bf495f7d6b4944aa395b3ab5293479>:0
at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00018] in <59551ad1b0244c86ada93d710ff2e802>:0
at SQLite.SQLiteCommand.ExecuteQuery[T] () [0x0001c] in <9945edc4c42e4621a31b5582964d5150>:0
at SQLite.TableQuery`1[T].ToList () [0x0000b] in <9945edc4c42e4621a31b5582964d5150>:0
at SQLite.AsyncTableQuery`1[T].<ToListAsync>b__11_0 (SQLite.SQLiteConnectionWithLock conn) [0x00000] in <9945edc4c42e4621a31b5582964d5150>:0
at SQLite.AsyncTableQuery`1+<>c__DisplayClass2_0`1[T,U].<ReadAsync>b__0 () [0x0001d] in <9945edc4c42e4621a31b5582964d5150>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <25bf495f7d6b4944aa395b3ab5293479>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
--- End of stack trace from previous location where exception was thrown ---
UPDATE: I wanted to add that the exception is only thrown, if the project setting Enable the Mono interpreter is disabled (which should be typically the case for the Release-build). You will not see the exception in Debug-configuration.
The existing PR doesn't really fix the problem, it just pushes the optimization of the generated run-time compiled code onto the consumer programmer. Maybe there is a way to compromise where the performance is increased but there doesn't need to be run-time compiled code. Try to generate code, if the platform doesn't support it fail over to the old way. Or maybe some way of providing a generic method on your class that will set the property without boxing.
With Visual Studio 2022 17.1 AOT and Interpreter work now. So this can used as a workaround too.
With Visual Studio 2022 17.1 AOT and Interpreter work now. So this can used as a workaround too.
This works very well, thank you!
@inforithmics @tualatin but to enable the mono interpreter should not be used for AppStore/Release builds as mentioned above by @thomaskaelin , right?
Wondering whether this will ever be adressed. This is pretty weird since
a) developer (@praeclarum) seems to have moved on to other projects or at least this project is not a priority. This is their prerogative, they have no obligation at all and I am thankful that they have built this library at all. b) Microsoft at the same time is pushing out content with MAUI that presents sqlite-net-pcl as a standard, mature and viable option for data storage. For example
- Microsoft Learn: https://learn.microsoft.com/en-us/training/modules/store-local-data/
- Youtube: https://youtu.be/ftDq-leq5OM?t=126
This error still occurs in Xamarin.Forms as well as MAUI for us, about a year after it first appeared. Currently, we are fixing our nuget dependency in csproj with square brackets like this
<!--Set to 1.7.335 due to https://github.com/praeclarum/sqlite-net/issues/1067 -->
<PackageReference Include="sqlite-net-pcl" Version="[1.7.335]" />
Will there ever be a resolution to this?
@Hottemax as they wrote, changing to enable the mono interpreter also avoid this error. Also the .ipa size was reduced by the half on my project. The main problem i have is that i don't know if its now a good practice to enable the mono interpreter for store builds. I was also afraid because of the apple store review, after a bit search i found this: https://stackoverflow.com/questions/61106892/are-we-allowed-to-publish-xamarin-ios-apps-with-the-mono-interpreter-enabled
Currently i'm at this point to finish the project. I will now try to send the build with "mono interpreter enabled" to app store review and tell you what happens if you want.
Question to you: Is this option no point for you? If not, why?
@stoff99 I have not checked this "workaround" because a) it is tedious to test since it only occurs on device, not while debugging etc. b) I am busy with other stuff, but mainly since c) it does not address the actual bug/issue.
Others will come after us, use MAUI/Xamarin and SQLite with default settings and latest versions, and not having found this thread, and their app will not work/break in production.
About the apple review: I sent in the app to the apple review and it was accepted without any problems.
About the apple review: I sent in the app to the apple review and it was accepted without any problems.
Yeah, this works at the moment without problems. But I hope, this bug will fix as soon as possible.
Any suggestions on how to get around this in a .Net Maui iOS app? The option to enable Mono interpreter In VS 17.4 Stable or 17.5 Preview isn't there any more...
As @Hottemax mentioned this is being pushed by Microsoft as a stable means of data storage for .Net Maui apps...
I'm having this issue
@breenbob try to add --interpreter to “Additional mtouch arguments”
Thanks for posting this guys. Totally saved my sanity!!
I have exactly this issue and rolling back to 1.7.335 works for me. Thanks @Hottemax for the [ ] trick.
Any news on this?
Any suggestions on how to get around this in a .Net Maui iOS app? The option to enable Mono interpreter In VS 17.4 Stable or 17.5 Preview isn't there any more...
As @Hottemax mentioned this is being pushed by Microsoft as a stable means of data storage for .Net Maui apps...
maybe
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
<UseInterpreter>true</UseInterpreter>
</PropertyGroup>
Almost 3 years passed, any updates on this, or this project is buried?