sqlite-net
sqlite-net copied to clipboard
.NET 8 / MAUI Issues on iOS Release Mode
Hi there,
when running the app in release mode on .NET 8/MAUI iOS you can't read or write from the database.
Analyzing the issue I figured out that it's related to MAUI setting <UseInterpreter>
to false
on release to increase performance. Setting it to true
will fix the issues with the database.
Can we somehow make sure that sqlite-net-sqlcipher also works without the interpreter enabled on iOS? It massively degrades the performance of the app.
Packages I'm using:
<PackageReference Include="sqlite-net-sqlcipher" Version="1.8.116" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.5" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.5" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.5" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.5" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.5" />
Discussion on the MAUI Repository regarding this issue: https://github.com/dotnet/maui/issues/13019
Bump!
Same here. Does this project still maintained? Looks like 0 activity in 2 years.
Yeah seems like 1.7.335 is the way to go
bump
Use these settings in Release:
<UseInterpreter>true</UseInterpreter>
<MtouchInterpreter>-all</MtouchInterpreter>
This means, "enable the interpreter, but don't use it on any project assemblies". Your app's assemblies will be AOT compiled as usual, but the interpreter will be available at runtime to handle any dynamically generated code.
The problem with running on iOS was caused by the addition of fast column setters #902. You need to remove or #ifdef the code that was added for fast column setters and it should work fine on iOS without the interpreter.
Xamarin End-of-life is in 3 months. After that, it won't be long before Xamarin apps no longer even build.
This issue needs to be addressed soon or this library is effectively dead.
Is there another way?
The problem with running on iOS was caused by the addition of fast column setters #902. You need to remove or #ifdef the code that was added for fast column setters and it should work fine on iOS without the interpreter.
This is the way. Isn't there new AOT-compatible techniques for doing this type of thing as well? What does Dapper do?
Even though Xamarin has gone away, this issue is relevant to MAUI developers who develop for iOS. I have had to downgrade to 1.7.335 and will be forced to stay there until something is done about this. It causes a hard crash of the app without even throwing an exception.
As a "MAUI developer who develops for iOS" having this exact issue, I had tried various things over several days (because release mode takes 10-15 minutes to build on my setup) and, fortunately, took a tack today that led me to this thread and the viable workaround. The comment @ckrutsinger made me consider whether or not there was an exception to be caught, and that I had laid some groundwork and might be in a good position to capture it if there was. I should also mention that while this thread is tagged as .NET 8, my project is currently building on .NET 7 (a distinction that doesn't appear to have any bearing).
What I can offer as a data point is this:
private async void onStartupTaskG(object sender, CheckedChangedEventArgs e)
{
Profile.Log($"YVKHU");
var acnxSqm = ACnx[SpecialPath.Sqm];
try
{
List<DBPI> sqmDbpisA = await
acnxSqm
.Table<DBPI>()
.ToListAsync();
Profile.Log($"{NewLine}{string.Join(NewLine, sqmDbpisA.Select(_ => _.description))}");
Profile.Log($"SNRZ3");
}
catch (Exception ex)
{
Profile.Log($"NPGBK: {ex.GetType().Name}{NewLine}{ex.Message}");
}
}
Before applying the "fix".
The Release build encountered the issue, and successfully logged the detailed ExecutionEngineException
.
BEGIN PASS
[4/30/2024 11:58:48 AM] YVKHU
[4/30/2024 11:58:48 AM] NPGBK: ExecutionEngineException
Attempting to JIT compile method
'(wrapper delegate-invoke) void <Module>:invoke_callvirt_void_DBPI_string (IVSoftware.Portable.Quatch.Primitives.DBPI,string)'
while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
Applied the basic workaround in the csproj file.
<PropertyGroup Condition="'$(TargetFramework)' == 'net7.0-ios'">
<UseInterpreter>True</UseInterpreter>
</PropertyGroup>
After applying the "fix".
The log now lists the query result, and the "SNRZ3" tag is further evidence a database query that successfully ran to completion.
BEGIN PASS
[4/30/2024 12:50:17 PM] YVKHU
[4/30/2024 12:50:17 PM]
Home
School
Storage Unit
Work
[4/30/2024 12:50:17 PM] SNRZ3
Hope this might be helpful.
Environment
Visual Studio 17.9.7 XCode 15.3 sqlite-net-pcl: 1.9.172 .NET 7