{"record":{"id":"ec8782675dc55cd7","repo":"dotnet/efcore","slug":"azure-cosmos-db-does-not-support-synchronous-i-o-ec8782","errorCode":null,"errorMessage":"Azure Cosmos DB does not support synchronous I/O. Make sure to use and correctly await only async methods when using Entity Framework Core to access Azure Cosmos DB.","messagePattern":"Azure Cosmos DB does not support synchronous I/O\\. Make sure to use and correctly await only async methods when using Entity Framework Core to access Azure Cosmos DB\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs","lineNumber":629,"sourceCode":"\n    private sealed class CosmosUpdateEntry\n    {\n        public required IUpdateEntry Entry { get; init; }\n        public required CosmosCudOperation Operation { get; init; }\n        public required string CollectionId { get; init; }\n        public required CosmosStructuralTypeSerializer Serializer { get; init; }\n    }\n\n    private sealed record Grouping(string ContainerId, PartitionKey PartitionKeyValue);\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public override int SaveChanges(IList<IUpdateEntry> entries)\n        => throw new InvalidOperationException(CosmosStrings.SyncNotSupported);\n}\n","sourceCodeStart":611,"sourceCodeEnd":631,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Storage/Internal/CosmosDatabaseWrapper.cs#L611-L631","documentation":"The Cosmos batch executor's synchronous SaveChanges override throws because the Cosmos SDK is async-only. Any call to the sync SaveChanges on a Cosmos-backed DbContext routes here and fails immediately.","triggerScenarios":"Calling dbContext.SaveChanges() (sync) on a Cosmos provider. Happens with sync repositories, sync test helpers, or library code that calls SaveChanges without an async overload.","commonSituations":"Reusing a sync generic repository against Cosmos. Legacy sync code paths. Libraries that hard-code SaveChanges().","solutions":["Call await dbContext.SaveChangesAsync(cancellationToken) instead.","Make the calling method async to propagate the await.","If you control the abstraction, expose only async save methods to prevent sync misuse."],"exampleFix":"// before\ndbContext.SaveChanges();\n\n// after\nawait dbContext.SaveChangesAsync();","handlingStrategy":"validation","validationCode":"if (dbContext.Database.ProviderName == \"Microsoft.EntityFrameworkCore.Cosmos\")\n{\n    throw new InvalidOperationException(\"Use SaveChangesAsync for Cosmos.\");\n}\ndbContext.SaveChanges();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Expose only async save methods in repositories used by Cosmos.","Make call sites async end-to-end.","Ban SaveChanges() in Cosmos projects via an analyzer/roslyn rule."],"tags":["cosmos","syncnotsupported","savechanges","async"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}