Azure Cosmos DB Preview Emulator with EF Core and Enrich API fails writing to the database
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
I've issues running my Codebreaker solution using the Azure Cosmos DB preview emulator with the Enrich API using EF Core - it's running with the local installed emulator, and in Azure. With the preview emulator it fails.
Now I tried using @davidfowl project https://github.com/davidfowl/aspire-ai-chat-demo. With the code as it is, everything runs successfully.
Changing it to use the .NET Aspire Enrich API, it fails.
### Expected Behavior
When changing ChatApi/Program.cs from
```csharp
builder.AddCosmosDbContext("conversations", "db");
```
https://github.com/davidfowl/aspire-ai-chat-demo/blob/6296a504010e77fce550c8f2aba893ed0e4f34cf/ChatApi/Program.cs#L7
to
```csharp
builder.Services.AddCosmos("conversations", "db");
builder.EnrichCosmosDbContext();
```
https://github.com/christiannagel/aspire-ai-chat-demo/blob/192969f0eb254b39639849b005f90db4ac5dcc84/ChatApi/Program.cs#L8-L9
No data is written to the database. I saw a `DbUpdateException`.
### Steps To Reproduce
_No response_
### Exceptions (if any)
```
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the item with id '0195aee7-e4da-7a43-be30-78fcc1faaecb'. See the inner exception for details.
---> System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary`2 parsetable, String connectionString, Boolean buildChain, Dictionary`2 synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms, Boolean useOdbcRules)
at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
at Microsoft.Azure.Cosmos.CosmosClientOptions.GetValueFromConnectionString[T](String connectionString, String keyName, T defaultValue)
at Microsoft.Azure.Cosmos.CosmosClientOptions.GetAccountEndpoint(String connectionString)
at Microsoft.Azure.Cosmos.CosmosClient..ctor(String connectionString, CosmosClientOptions clientOptions)
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.SingletonCosmosClientWrapper.get_Client()
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.get_Client()
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.CreateItemOnceAsync(DbContext _, ValueTuple`4 parameters, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.CreateItemOnceAsync(DbContext _, ValueTuple`4 parameters, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClientWrapper.CreateItemOnceAsync(DbContext _, ValueTuple`4 parameters, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseWrapper.SaveChangesAsync(IList`1 entries, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseWrapper.SaveChangesAsync(IList`1 entries, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(StateManager stateManager, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass30_0`2.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at ChatExtensions.<>c.<b__0_3>d.MoveNext() in D:\christian\aspire-ai-chat-demo\ChatApi\ChatApi.cs:line 46
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass101_2.<b__2>d.MoveNext()
```
I don't know how this relates to changing the configuration to the Enrich API.
### .NET Version info
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.