András Tóth‘s professional blog
banditoth.net

Hey there 👋, I’m banditoth a .NET MAUI developer from Hungary.
I write about software development with .NET technologies.

You can find me on:
LinkedIn | Github | StackOverflow | X / Twitter | Threads

Tag: database

  • Resolving SQLite issues for .NET MAUI

    This content has 7 months. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Recently, while working on ExampleApp, we faced two significant errors and found effective solutions for both. Here’s a detailed account of the problems and their resolutions.

    System.TypeInitializationException

    System.TypeInitializationException: The type initializer for 'SQLite.SQLiteConnection' threw an exception.
     ---> System.DllNotFoundException: e_sqlite3
    

    To resolve this error, we needed to install the latest NuGet package for SQLitePCLRaw.bundle_green. This package ensures that the necessary SQLite libraries are included in the project.

    Add the following package reference with the latest version to your project:

    <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.10" />
    
    

    In the AppDelegate.cs file, add the following line to the CreateMauiApp method:

    protected override MauiApp CreateMauiApp()
    {
        SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());
        return MauiProgram.CreateMauiApp();
    }
    

    System.ExecutionEngineException in iOS Release Mode

    System.ExecutionEngineException: Attempting to JIT compile method '(wrapper delegate-invoke) void System.Action`2<ExampleApp.Entites.LocalDatabase.VoucherLite, double>:invoke_callvirt_void_T1_T2 (ExampleApp.Entites.LocalDatabase.VoucherLite,double)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.
    

    This error occurs due to the JIT compilation attempt in AOT-only mode on iOS. The solution is to install this specific version of the sqlite-net-pcl.
    It will ONLY work with 1.7.355 or below.

    <PackageReference Include="sqlite-net-pcl" Version="1.7.335" />
    

     This solution is also applicable to Xamarin projects.