Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dizmus opened this issue Sep 17, 2021 · 45 comments

Comments

@Dizmus
Copy link

Dizmus commented Sep 17, 2021

Steps to reproduce:

  1. Create Xamarin.iOS application
  2. Create SQLAsyncConnection
  3. Access Entity via Table().FindOneAsync

Error:

Attempting to JIT compile method '(wrapper delegate-invoke) void :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].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 ---

@RemcoDEV
Copy link

RemcoDEV commented Sep 29, 2021

We experience this issue too using FirstOrDefaultAsync:

image

await Database.Table().FirstOrDefaultAsync()

@twelve-cgn
Copy link

Same Problem here with GetAllWithChildren():
image

@suihanhbr
Copy link

same problem with SQLiteConnection.Query()

@InquisitorJax
Copy link

stack trace for me:
Attempting to JIT compile method '(wrapper delegate-invoke) void :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].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 ---

@thedee
Copy link

thedee commented Nov 2, 2021

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

@lukealderton
Copy link

I'm having the same issue as above, I've tried, .Table().Where(x => x...) and .Query("query"), same issue, also with using 'ugly' I thought it might solve the issue, but still getting the same issue

@paul-kiar
Copy link

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

@inforithmics
Copy link
Contributor

pull request with workaround

#1064

@ElteHupkes
Copy link
Contributor

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.

@inforithmics
Copy link
Contributor

inforithmics commented Nov 12, 2021

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.

mono/mono#20417

Which seems not been merged yet into the release mono runtime.

@inforithmics
Copy link
Contributor

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.

#1064

@AppsmithsLLC
Copy link

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

@StepKie
Copy link

StepKie commented Jan 27, 2022

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

@thomaskaelin
Copy link

thomaskaelin commented Jan 28, 2022

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.

@paul-kiar
Copy link

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.

@inforithmics
Copy link
Contributor

inforithmics commented Feb 16, 2022

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

@tualatin
Copy link

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!

@stoff99
Copy link

stoff99 commented Sep 27, 2022

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

@StepKie
Copy link

StepKie commented Sep 29, 2022

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

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?

@stoff99
Copy link

stoff99 commented Sep 29, 2022

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

@StepKie
Copy link

StepKie commented Sep 30, 2022

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

@stoff99
Copy link

stoff99 commented Oct 13, 2022

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

@tualatin
Copy link

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.

@breenbob
Copy link

breenbob commented Dec 8, 2022

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

@bwinklesky
Copy link

I'm having this issue

@stoff99
Copy link

stoff99 commented Dec 12, 2022

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

@p3john
Copy link

p3john commented Jan 3, 2023

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.

@twelve-cgn
Copy link

Any news on this?

@Madde88
Copy link

Madde88 commented Jun 17, 2023

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>

@SergTomcat
Copy link

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

@sencagri
Copy link

We are facing this issue with .NET MAUI now. And interpreter is not working also. Is there any method we can check the interpreter is really working?

@ognjensuljagic
Copy link

@praeclarum
Any thoughts about this?

@phillippschmedt
Copy link

Facing a similar issue with .NET MAUI. Using the Interpreter works for us but had bad impact on the overall performance. Is there any way to fix this?

@stoff99
Copy link

stoff99 commented Jan 12, 2024

@phillippschmedt you talking about debug or did you try also with release config?
For me, the performance in debug is bad. In the release build, it works as expected.

@phillippschmedt
Copy link

phillippschmedt commented Jan 13, 2024

@stoff99 I am talking about the general app performace in release mode. Like navigating etc. It slows down for me when enabling the interpreter.

@pme442
Copy link

pme442 commented Jan 24, 2024

Any updates?

@jonebersole
Copy link

This is still an issue as of 4/4/24 using any of the two latest sqlite-net-pcl versions above 1.7.335 in .NET MAUI. (yes, it worked for me after downgrading from the 1.8.116 and the most current 1.9.172) That will teach me to upgrade any nuget components unless absolutely mandatory for feature requirements or security reasons. It feels like every time I do, I end up with more problems than I started with. I guess they don't make 'em like they used to. I lost about 10hrs of testing and research until I finally landed here, only to be disappointed that I have to go backwards instead of forward to fix my issue. If I was the one that broke this feature, I'd sure try to make time to fix it before moving on to something else. But that's just me. I greatly appreciate all of the contributors and their feedback to this problem. It helped and saved me probably another 10hrs of frustration. Now, I get to go back in and find all of the things I changed during testing (that I doubted) and get it back to work again. :-)

@JeroenBer
Copy link
Contributor

I had the same problem on iOS running net8.0-ios release mode app using sqlite-net-pcl v1.8.116

Stacktrace pointing to same issue:

at SQLite.FastColumnSetter.<>
at SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__12`1

In this case I am using the query method like:

DbConnection.Query<Entity>("SELECT * FROM Entity WHERE ...")

The solution with UseInterpreter does work, however that's not what you would like.

<UseInterpreter>true</UseInterpreter>

I was quite surprised this still isn't fixed. Without investigating the source but after reading the comments I think the needs to check if dynamic code is supported:

System.Runtime.CompilerSerivces.RuntimeFeatures.IsDynamicCodeSupported 

See https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.runtimefeature.isdynamiccodesupported?view=netstandard-2.1#system-runtime-compilerservices-runtimefeature-isdynamiccodesupported

After some more investigation the strange thing was that for some DbConnection.Query calls it worked fine but some crashed. After some more investigation I was able to fix my problem. It depended on the definition of the type you are querying into:

In my case something like (simplified for example):

public class Entity : IEntity
{
	public Guid A { get; set; }
	public Guid B { get; set; }
}

public interface IEntity
{
	public Guid A { get; set; }
	public Guid B { get; set; }
}

The difference with the other queries were the setters on the interface. After removing the interface setters (which I didn't need) everything worked fine like:

public class Entity : IEntity
{
	public Guid A { get; set; }
	public Guid B { get; set; }
}

public interface IEntity
{
	public Guid A { get; } // REMOVED SETTER
	public Guid B { get; } // REMOVED SETTER
}

The moral is maybe it does work if you are querying into plain POCO objects without interfaces, etc ? Does anyone have the same experience ?
So maybe the workaround is make sure you are quering into simple objects (without interfaces, inheritance, whatever) and after the query turn them into whatever it needs to be...

@phillippschmedt
Copy link

phillippschmedt commented Apr 6, 2024

@JeroenBer As already mentioned in other discussions the issue was introduced with this PR which uses code generation: #902 - I took the latest master, removed these parts and copied the files to my project. Everything runs fine again.

@gtrafford
Copy link

gtrafford commented Apr 17, 2024

I had the same problem on iOS running net8.0-ios release mode app using sqlite-net-pcl v1.8.116

Stacktrace pointing to same issue:

at SQLite.FastColumnSetter.<>
at SQLite.SQLiteCommand.<ExecuteDeferredQuery>d__12`1

In this case I am using the query method like:

DbConnection.Query<Entity>("SELECT * FROM Entity WHERE ...")

The solution with UseInterpreter does work, however that's not what you would like.

<UseInterpreter>true</UseInterpreter>

I was quite surprised this still isn't fixed. Without investigating the source but after reading the comments I think the needs to check if dynamic code is supported:

System.Runtime.CompilerSerivces.RuntimeFeatures.IsDynamicCodeSupported 

See https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.runtimefeature.isdynamiccodesupported?view=netstandard-2.1#system-runtime-compilerservices-runtimefeature-isdynamiccodesupported

After some more investigation the strange thing was that for some DbConnection.Query calls it worked fine but some crashed. After some more investigation I was able to fix my problem. It depended on the definition of the type you are querying into:

In my case something like (simplified for example):

public class Entity : IEntity
{
	public Guid A { get; set; }
	public Guid B { get; set; }
}

public interface IEntity
{
	public Guid A { get; set; }
	public Guid B { get; set; }
}

The difference with the other queries were the setters on the interface. After removing the interface setters (which I didn't need) everything worked fine like:

public class Entity : IEntity
{
	public Guid A { get; set; }
	public Guid B { get; set; }
}

public interface IEntity
{
	public Guid A { get; } // REMOVED SETTER
	public Guid B { get; } // REMOVED SETTER
}

The moral is maybe it does work if you are querying into plain POCO objects without interfaces, etc ? Does anyone have the same experience ? So maybe the workaround is make sure you are quering into simple objects (without interfaces, inheritance, whatever) and after the query turn them into whatever it needs to be...

I found the exact same issue. Between versions of my app all of a sudden I was getting this error on iOS unless I enabled the mono interpreter. Couldn't figure out why. Hadn't updated any libraries. Your comment pointed me in the right direction. I had changed one of my existing classes to implement an interface. Undoing that fixed it. I can also confirm that removing the setters fixed it, however I need those so that doesn't work for me.

@JRC-BitBull
Copy link

@JeroenBer As already mentioned in other discussions the issue was introduced with this PR which uses code generation: #902 - I took the latest master, removed these parts and copied the files to my project. Everything runs fine again.

Hi,

Any chance you could elaborate on how to do this? I've dowloaded the latest repo but I can't figure out which bits of code I need to remove or how to explicitly remove that commit (also it says here that it's MakeGenericMethod that's the problem, I can find that in the source but i can't see a reference to it in that commit).

Tried rolling back to 1.7.x but that's giving me other issues.

cheers

@Madde88
Copy link

Madde88 commented Aug 28, 2024

Maybe this can be a workaround - enable the interpreter for only needed assemblies.

	<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
		<MtouchInterpreter>-all,sqlite-net-pcl</MtouchInterpreter>
	</PropertyGroup>

@AncientLust
Copy link

@Madde88 thank you so much! About 5 issues are created around this problem. Just to sum up all solutions gathered around (all worked in my case) from best to worst IMO:

  1. Put into interpreter only sqlite-net-pcl library via solution @Madde88 mentioned.
  2. Rollback your sqlite-net-pcl library back to 1.7.335. Fastest way, yet comes with downsides which depend on your use cases.
  3. Fetch main of the library repo, revert PR which introduced the issue and use this assembly in your project.
  4. Enable interpreter via <UseInterpreter>true</UseInterpreter> for release. This will significantly slowdown page navigation and probably add other performance issues.

@StepKie
Copy link

StepKie commented Oct 14, 2024

the silence by @praeclarum is so weird - since there were even new releases, and this is the most commented on issue in the entire repository.
As I lined out in a post over 2 years ago:

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

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?

We still have no idea what is going here, or what we can do to support @praeclarum to incorporate a fix, besides creating a PR for it, which has been done already?

@mackayn
Copy link

mackayn commented Oct 14, 2024

the silence by @praeclarum is so weird - since there were even new releases, and this is the most commented on issue in the entire repository. As I lined out in a post over 2 years ago:

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

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?

We still have no idea what is going here, or what we can do to support @praeclarum to incorporate a fix, besides creating a PR for it, which has been done already?

Maybe if they didn't inexplicably drop him as an MVP he'd maybe feel a little more invested, considering the plugin is used by most MAUI store apps. Went with using the interpreter in the short term and really noticed no performance issues in release mode but will tweak to use the approach @Madde88 outlined when we make a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests