microsoft / appcenter-sdk-dotnet

Development repository for the App Center SDK for .NET platforms, including Xamarin
Other
311 stars 141 forks source link

Using AppCenter.Start() with OfflineSQLiteStore in Maui iOS causes SQLite MISUSE and throws "Unable to configure sqlite3 for URI connection strings." #1725

Closed ryanlpoconnell closed 1 year ago

ryanlpoconnell commented 1 year ago

Description

Using AppCenter.Start() with OfflineSQLiteStore() in Maui iOS causes SQLite MISUSE and throws "Unable to configure sqlite3 for URI connection strings.".

The following line of code will fail for Maui iOS if AppCenter.Start() is called during startup (But works as expected with Maui Android)... var store = new OfflineSQLiteStore(connectionString);

To clarify using OfflineSQLiteStore from Microsoft.Datasync.Client.SQLiteStore works for Maui iOS using simplified example code from ... https://learn.microsoft.com/en-us/azure/developer/mobile-apps/azure-mobile-apps/quickstarts/maui/offline?pivots=vs2022-mac ... until using this line in App.xaml.cs > OnStart() Microsoft.AppCenter.AppCenter.Start("ios=appid;android=appid",typeof(Microsoft.AppCenter.Analytics.Analytics), typeof(Microsoft.AppCenter.Crashes.Crashes));

Exception.Message = "Unable to configure sqlite3 for URI connection strings." Exception.Source. ="Microsoft.Datasync.Client.SQLiteStore"

NOTE: I believe the message re URI is a red herring due to the way any non-success result is handled in SQLiteConnection

if (raw.sqlite3_config (17, 1) != 0) {
      throw new SQLiteException ("Unable to configure sqlite3 for URI connection strings.");
}

Developer is only able to determine sqlite misuse error response RE Application output (see repro steps)

Repro Steps

Please list the steps used to reproduce your issue.

  1. Use provided zip example Maui project MauiAppCenterSqliteMisuse.zip
  2. Select Debug > iPhone Simulator (to produce in Maui iOS)
  3. Run the example App and click the button called Initialise Sqlite (see screenshot below)
  4. Note Sqlite failure in Application Output: "2023-01-23 14:56:01.770644+0000 MauiAppCenterSqlite[11274:199190] [logging] misuse at line 179186 of [554764a6e7]"
  5. Example App catches exception to display ex.Message "Unable to configure sqlite3 for URI connection strings."
  6. To prove Microsoft.AppCenter.AppCenter.Start is contributing to this issue, comment the line of code in App.xaml.cs > OnStart() > Line 19 and repeat steps 1-5

Details

  1. Using Microsoft.AppCenter SDKs version 5.0.1
  2. Using Microsoft.Datasync.Client.SQLiteStore SDK version 5.0.20
  3. iOS 16.2 (iPhone 14 Pro Max)
  4. XCode 14.2

Screenshot

Simulator Screen Shot - iPhone 14 Pro Max - 2023-01-23 at 15 04 46

DmitriyKirakosyan commented 1 year ago

Hi @ryanlpoconnell , thank you for contacting us!

This looks like a conflict of sqlite3 usage of AppCenter SDK and Microsoft.Datasync.Client.SQLiteStore. Based on the source that the exception comes from, I would suggest you to open an issue in azure-mobile-apps repo.

Meanwhile we are still looking into it and will update on progress.

ryanlpoconnell commented 1 year ago

I have duplicated the issue under https://github.com/Azure/azure-mobile-apps/issues/573 as you have suggested.

ryanlpoconnell commented 1 year ago

RE https://github.com/Azure/azure-mobile-apps/issues/573 this has been Closed but unactioned as apparently it does not have "official support".

I understand the problem is two components incompatible due to depending on the same underlying library...

But given that under time pressure I will need to choose one of these libraries to ditch, it would need to be AppCenter...

Is there any scope for compatibility to be addressed as part of the AppCenter team?

I still think it is ludicrous that two mobile centric Microsoft components cannot work together and that there are no plans for Microsoft to address this.

Arslan007 commented 1 year ago

Facing same issue in our app too.

DmitriyKirakosyan commented 1 year ago

@ryanlpoconnell @Arslan007 after looking into it, here is what I found

raw.sqlite3_config(raw.SQLITE_CONFIG_URI, 1) returns (21) SQLITE_MISUSE (see https://sqlite.org/rescode.html).

OfflineSQLiteStore throws exeption if setting raw.SQLITE_CONFIG_URI doesn't return SQLITE_OK. I believe this behaviour can be improved avoiding throwing, as it is done in app center sdk.

The reason why SQLITE_MISUSE is returned is because the AppCenter SDK already set this flag. See MSACDBStorage.m#L542. However sdk doesn't throw if setting the flag fails. See MSACDBStorage.m#L41.

So, there is nothing AppCenter SDK can do to solve this issue. It should be fixed on the azure-mobile-apps side.


WORKAROUND

Initialize OfflineSQLiteStore first, then call AppCenter.Start. This way OfflineSQLiteStore will set the flag successfully, then AppCenter SDK will fail setting the flag but won't crash. After that, you will be OK using both libs.

DmitriyKirakosyan commented 1 year ago

I'm closing it as not an SDK issue.

Arslan007 commented 1 year ago

@DmitriyKirakosyan Thanks for looking into it. Yes it worked.