EntityFrameworkCore.Cosmos preview 3 - Not Found Error

asp.net-core azure-cosmosdb entity-framework-core

Question

I am trying to use the new EntityFrameworkCore.Cosmos Preview 3 package in an ASP.NET Core website, but I keep getting an error back when trying to Create the DB. I can't seem to find any documentation to give me an idea of what is causing the error.

In my Startup.cs file in the ConfigureServices method I have the following code:

// Configure EntityFramework - CosmosDB
services.AddDbContext<EFContext>(options => options.UseCosmos(
    authKeyOrResourceToken: ServiceFactory.GetDbKeySecret(_config, (_hosting.EnvironmentName != "LocalDev")),
    serviceEndPoint: _config.GetValue<string>("CosmosDb:Endpoint"),
    databaseName: _config.GetValue<string>("CosmosDb:DatabaseID")
));
EFContext efc = services.BuildServiceProvider().GetRequiredService<EFContext>();
efc.Database.EnsureCreatedAsync().Wait();

When it gets to the last line I get the below error (stack trace):

at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosClient.CreateDatabaseIfNotExistsOnceAsync(DbContext _, Object __, 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.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Cosmos.Storage.Internal.CosmosDatabaseCreator.EnsureCreatedAsync(CancellationToken cancellationToken)

And with Fiddler the detailed response is: "{"code":"NotFound","message":"Entity with the specified id does not exist in the system.\r\nActivityId: 6aed2df0-abe8-4e93-b468-b3188005fcb5, Microsoft.Azure.Documents.Common/2.1.0.0"}"

I have checked and double checked all the values in my config are correct and match to my CosmosDB account in Azure, but I still can't figure out what is causing this error.

Has anyone run into this and have a solution? Thanks

1
0
11/7/2018 3:19:37 AM

Popular Answer

I found a similar issue previously posted (Azure Cosmos DB - CreateDatabaseAsync - Resource Not Found) where someone had the same kind of issue and resolved it by deleting the DB and recreating. I tried the same thing and found that my code works as expected.

I guess there was some error during creation that was never reported (or I missed an error message somewhere) with the original CosmosDB Account creation. So if anyone is getting similar message, try recreating your account.

0
11/7/2018 3:01:47 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow