System,Data.sqlite showing System.BadFormatException: Method has no body in xamarin.android

Vinoth Swami 1 Reputation point
2021-02-28T06:44:42.547+00:00

When I create a sqlconnection config it showing exception. I can build and run the app in stimulator as well as Device.

the App getting crash when i configure to SqliteConnection.SetConfig.

please help me to fix this.72695-sqlie-issue.png

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,292 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,666 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-03-01T09:39:09.09+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    The Android version of SQLite has a limitation that requires a few more steps. If the call to SqliteConnection.SetConfig produces a SQLite exception such as library used incorrectly, then you must use the following workaround:

    1.Link to the native libsqlite.so library so that the sqlite3_shutdown and sqlite3_initialize APIs are made available to the app:

        [DllImport("libsqlite.so")]  
    internal static extern int sqlite3_shutdown();  
    
    [DllImport("libsqlite.so")]  
    internal static extern int sqlite3_initialize();  
    

    2.At the very beginning of the OnCreate method, add this code to shutdown SQLite, configure it for Serialized mode, and reinitialize SQLite:

      using using Mono.Data.Sqlite;  
    ...  
    sqlite3_shutdown();  
    SqliteConnection.SetConfig(SQLiteConfig.Serialized);  
    sqlite3_initialize();  
    

    Refer : https://learn.microsoft.com/en-us/xamarin/android/data-cloud/data-access/using-sqlite-orm#using-sqlitenet-with-multiple-threads

    Best Regards,

    Jessie Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.