I am trying to create a MAUI app with offline data sync.
I am getting the above error on Android emulator when calling the Sync method. The sync runs well when debugging on windows app. below is my code
public async Task SyncAsync()
{
if (!_initialized)
return;
ReadOnlyCollection<TableOperationError> syncErrors = null;
try
{
//foreach (var offlineTable in offlineTables.Values)
//{
var pullOptions = new PullOptions { PushOtherTables = true, WriteDeltaTokenInterval = 25 };
await table.PullItemsAsync(pullOptions); //Error here...
await table.PushItemsAsync();
//}
}
catch (PushFailedException exc)
{
if (exc.PushResult != null)
{
syncErrors = (ReadOnlyCollection<TableOperationError>)exc.PushResult.Errors;
}
}
}
This is how I initialize my offline definition
private async void Init()
{
if (_initialized) return;
//Create offline definition
var dbPath = Path.Combine(FileSystem.AppDataDirectory, "todoitems.db");
//var store = new OfflineSQLiteStore($"file:/{dbPath}?mode=rwc");
var connectionString = new UriBuilder
{
Scheme = "file",
Path = dbPath,
Query = "?mode=rwc"
}.Uri.ToString();
var store = new OfflineSQLiteStore(connectionString);
store.DefineTable<ToDo>();
var options = new DatasyncClientOptions
{
OfflineStore = store,
//IdGenerator = (table) => Guid.NewGuid().ToString("N"),
InstallationId = null,
//ParallelOperations = 1,
SerializerSettings = null,
//TableEndpointResolver = (table) => $"/tables/{tableName.ToLowerInvariant()}",
UserAgent = $"Datasync/5.0 (/* Device information */)"
};
//Create the data sync client
string baseAddress = DeviceInfo.Platform == DevicePlatform.Android ? "https://10.0.2.2:7067" : "https://localhost:7067";
client = new DatasyncClient(baseAddress, options);
//Initialize database
await client.InitializeOfflineStoreAsync();
//Get reference to the offline table
table = client.GetOfflineTable<ToDo>();
// Set _initialized to true to prevent duplication of locking.
_initialized = true;
}
And below is the screenshot of the error:
