Skip to content

Unable to push more than one table at a time #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
taddisateesh opened this issue Apr 22, 2025 · 4 comments
Open

Unable to push more than one table at a time #335

taddisateesh opened this issue Apr 22, 2025 · 4 comments
Labels
Awaiting Response Awaiting response from the OP Client Improvements or additions to the client code stale Stale issue or PR.

Comments

@taddisateesh
Copy link

taddisateesh commented Apr 22, 2025

Describe the bug

I am trying to push the pending changes in all tables. Unfortunately i am getting below exception.Please find below code snippet and exception details.

Code snippet:

 public async Task UpdateItemAsync(T item, CancellationToken token = default(CancellationToken))
    {
        try
        {
            
           using (var dbContext = new AppDbContext(dbContextOptionsBuilder.Options))
            {
                dbContext.TokenRequester = TokenRequester;
                await ClearExistingQueue(dbContext, typeof(T));
                dbContext.Set<T>().Update(item);
                //await IncludeRelatedEntitiesAsync(dbContext, item);
                await dbContext.SaveChangesAsync();
                if (IsConnected)
                {
                     await dbContext.PushAsync([ typeof(ConstructionDto), typeof(ConstructionAddressDto) ]);
                }
            }
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }



 public async Task ClearExistingQueue(AppDbContext context, Type entityType, bool isSaveContext = false)
    {
        try
        {
            List<DatasyncOperation> pendingOperations = await context.DatasyncOperationsQueue.Where(x => x.EntityType == entityType.FullName!).ToListAsync();
            context.RemoveRange(pendingOperations);

            List<DatasyncDeltaToken> deltaTokens = await context.DatasyncDeltaTokens.Where(x => x.Id.Contains(entityType.FullName!)).ToListAsync();
            context.RemoveRange(deltaTokens);
            if ((pendingOperations != null && pendingOperations.Any()) || (deltaTokens != null && deltaTokens.Any()) && isSaveContext)
            {
                await context.SaveChangesAsync();
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }
    }

exception details :
System.InvalidOperationException: This instance has already started one or more requests. Properties can only be modified before sending the first request.
at System.Net.Http.DelegatingHandler.CheckDisposedOrStarted()
2025-04-22 18:04:50.317054+0530 ClientApp[23038:480165] at System.Net.Http.DelegatingHandler.set_InnerHandler(HttpMessageHandler value)
at CommunityToolkit.Datasync.Client.Http.HttpClientFactory.CreatePipeline(IEnumerable1 handlers) at CommunityToolkit.Datasync.Client.Http.HttpClientFactory.GenerateClient() 2025-04-22 18:04:50.317163+0530 ClientApp[23038:480165] at CommunityToolkit.Datasync.Client.Http.HttpClientFactory.CreateClient(String name) at CommunityToolkit.Datasync.Client.Offline.Models.OfflineOptions.GetOptions(Type entityType) 2025-04-22 18:04:50.317293+0530 ClientApp[23038:480165] at CommunityToolkit.Datasync.Client.Offline.OperationsQueue.OperationsQueueManager.PushOperationAsync(DatasyncOperation operation, CancellationToken cancellationToken) at CommunityToolkit.Datasync.Client.Offline.OperationsQueue.OperationsQueueManager.<>c__DisplayClass20_0.<<PushAsync>b__1>d.MoveNext() 2025-04-22 18:04:50.317398+0530 ClientApp[23038:480165] --- End of stack trace from previous location --- at CommunityToolkit.Datasync.Client.Offline.OperationsQueue.OperationsQueueManager.PushAsync(IEnumerable1 entityTypes, PushOptions pushOptions, CancellationToken cancellationToken)
2025-04-22 18:04:50.317543+0530 ClientApp[23038:480165] at ClientApp.Data.Services.DataSyncService`1.d__20[[ClientApp.Data.Models.ConstructionDto, ClientApp.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() in /Users/sateesh/Documents/Projects/Inspection_new/ClientApp.Data/Services/DataSyncService.cs:line 409

  • Client:
    • What platform (Android, iOS, Windows, etc.) versions are you running on?
    • iOS and Android
    • Does it happen in an emulator / simulator, or only on a real device?
    • Both
    • Version of dotnet being used to compile?
    • 9.0.1
    • .NET Runtime Environment (WPF, UWP, WinUI3, MAUI, etc.):
    • MAUI
    • Datsync Toolkit NuGet versions?
    • 9.0.1
    • GitHub repository containing the code (optional, but helps!)

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

@taddisateesh taddisateesh added the Requires Triage This issue has not been checked by the project team. label Apr 22, 2025
@taddisateesh
Copy link
Author

@adrianhall FYI..

@taddisateesh
Copy link
Author

@adrianhall Any update on this issue ?

@adrianhall
Copy link
Collaborator

Just got back from vacation - a quick test setup did not prove fruitful, in that I could not re-produce the specific problem. Can you provide an xUnit style test (as a PR) that shows the problem.

@adrianhall adrianhall added Client Improvements or additions to the client code Awaiting Response Awaiting response from the OP and removed Requires Triage This issue has not been checked by the project team. labels May 9, 2025
Copy link

We have noticed this issue has not been updated within 21 days. If there is no action on this issue in the next 14 days, we will automatically close it.

@github-actions github-actions bot added the stale Stale issue or PR. label May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Response Awaiting response from the OP Client Improvements or additions to the client code stale Stale issue or PR.
Projects
None yet
Development

No branches or pull requests

2 participants