sqlite-net icon indicating copy to clipboard operation
sqlite-net copied to clipboard

Not working on iOS after 1.8.116 - Attempting to JIT compile method '(wrapper delegate-invoke)

Open Dizmus opened this issue 3 years ago • 43 comments

Steps to reproduce:

  1. Create Xamarin.iOS application
  2. Create SQLAsyncConnection
  3. 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__121[T].MoveNext () <0x1059e7ec4 + 0x0031f> in <01c96d411fe34bd5940c99a56515582b#a6464d95a03c7bacba393abaab79514c>:0 at System.Collections.Generic.List1[T].AddEnumerable (System.Collections.Generic.IEnumerable1[T] enumerable) <0x104f40934 + 0x000b3> in <da8885cdf78b449d96de00cdb9d47225#a6464d95a03c7bacba393abaab79514c>:0 at System.Collections.Generic.List1[T]..ctor (System.Collections.Generic.IEnumerable1[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.TableQuery1[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.Expression1[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_01[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 ---

Dizmus avatar Sep 17 '21 15:09 Dizmus

We experience this issue too using FirstOrDefaultAsync:

image

await Database.Table<T>().FirstOrDefaultAsync()

RemcoDEV avatar Sep 29 '21 13:09 RemcoDEV

Same Problem here with GetAllWithChildren(): image

twelve-cgn avatar Oct 01 '21 09:10 twelve-cgn

same problem with SQLiteConnection.Query<T>()

suihanhbr avatar Oct 30 '21 10:10 suihanhbr

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__121[T].MoveNext () <0x103e9843c + 0x0031b> in <01c96d411fe34bd5940c99a56515582b#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at System.Collections.Generic.List1[T].AddEnumerable (System.Collections.Generic.IEnumerable1[T] enumerable) <0x100f2d75c + 0x000b3> in <218435b0f6654ac1ab0cdd176f26b9bd#a4fcafd7c547d2e8197af938ed6ad9c4>:0 at System.Collections.Generic.List1[T]..ctor (System.Collections.Generic.IEnumerable1[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_01[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.Task1[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 ---

InquisitorJax avatar Nov 01 '21 11:11 InquisitorJax

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 ---

thedee avatar Nov 02 '21 04:11 thedee

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

lukealderton avatar Nov 02 '21 12:11 lukealderton

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

paul-kiar avatar Nov 11 '21 17:11 paul-kiar

pull request with workaround

https://github.com/praeclarum/sqlite-net/pull/1064

inforithmics avatar Nov 11 '21 17:11 inforithmics

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.

ElteHupkes avatar Nov 12 '21 14:11 ElteHupkes

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.

inforithmics avatar Nov 12 '21 21:11 inforithmics

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

inforithmics avatar Nov 16 '21 13:11 inforithmics

It may not work for everyone, but I downgraded to 1.7.335 and my queries are working again.

AppsmithsLLC avatar Dec 06 '21 19:12 AppsmithsLLC

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

StepKie avatar Jan 27 '22 17:01 StepKie

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.

thomaskaelin avatar Jan 28 '22 15:01 thomaskaelin

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.

paul-kiar avatar Jan 28 '22 15:01 paul-kiar

With Visual Studio 2022 17.1 AOT and Interpreter work now. So this can used as a workaround too. image

inforithmics avatar Feb 16 '22 07:02 inforithmics

With Visual Studio 2022 17.1 AOT and Interpreter work now. So this can used as a workaround too. image

This works very well, thank you!

tualatin avatar Sep 23 '22 08:09 tualatin

@inforithmics @tualatin but to enable the mono interpreter should not be used for AppStore/Release builds as mentioned above by @thomaskaelin , right?

stoff99 avatar Sep 27 '22 12:09 stoff99

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?

StepKie avatar Sep 29 '22 10:09 StepKie

@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 avatar Sep 29 '22 11:09 stoff99

@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.

StepKie avatar Sep 30 '22 12:09 StepKie

About the apple review: I sent in the app to the apple review and it was accepted without any problems.

stoff99 avatar Oct 13 '22 09:10 stoff99

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.

tualatin avatar Oct 14 '22 07:10 tualatin

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...

Screenshot 2022-12-08 at 19 16 29

As @Hottemax mentioned this is being pushed by Microsoft as a stable means of data storage for .Net Maui apps...

breenbob avatar Dec 08 '22 19:12 breenbob

I'm having this issue

bwinklesky avatar Dec 10 '22 22:12 bwinklesky

@breenbob try to add --interpreter to “Additional mtouch arguments”

stoff99 avatar Dec 12 '22 07:12 stoff99

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.

p3john avatar Jan 03 '23 15:01 p3john

Any news on this?

twelve-cgn avatar Mar 31 '23 08:03 twelve-cgn

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...

Screenshot 2022-12-08 at 19 16 29

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>

Madde88 avatar Jun 17 '23 19:06 Madde88

Almost 3 years passed, any updates on this, or this project is buried?

SergTomcat avatar Jul 12 '23 14:07 SergTomcat