Skip to content

[WebToolsE2E][Aspire] After adding Aspire.Microsoft.EntityFrameworkCore.Cosmos, add related code to the program.cs shows error: There is no argument given that corresponds to the required parameter 'databaseName' ... #873

@v-cazhang

Description

@v-cazhang

INSTALL STEPS

  1. Clean machine: Win11 x64 23h2 ENU
  2. Install VS 17.9 P1

REPRO STEPS

  1. In the VS, create a new project > ASP.NET Core Web App (Model-View-Controller) > .NET 8.0 > none > check 'Enlist in Aspire Orchestration' > Create.
  2. Right-click the Models folder and add a new class file named Movie.cs, paste following codes:
public class Movie
	{
	    public int ID { get; set; }
	    public string Title { get; set; } = string.Empty;
	    public DateTime ReleaseDate { get; set; }
	    public string Genre { get; set; } = string.Empty;
	    public decimal Price { get; set; }
	}
  1. Right-click the Controllers folder > Add > Controller > MVC Controller with views, using Entity Framework

    • Model class: Movies.cs
    • DbContext class: click '+' to create a new db context
    • Database provider: select Azure Cosmos DB
  2. Right-click web project > Add > Aspire component > Aspire.Microsoft.EntityFrameworkCore.Cosmos > install

  3. Open appsettings.json file of web project, add following codes:

"Aspire": {
	    "Microsoft": {
	      "EntityFrameworkCore": {
	        "Cosmos": {
	          "DbContextPooling": true,
	          "Tracing": false
	        }
	      }
	    }
	  }
  1. Open Program.cs file of web project, add following code:
    builder.AddCosmosDbContext<MyDbContext>("myConnection");

ACTUAL
Shows error under 'AddCosmosDbContext;':
There is no argument given that corresponds to the required parameter 'databaseName' of 'AspireAzureEFCoreCosmosDBExtensions.AddCosmosDbContext(IHostApplicationBuilder, string, string, Action?, Action?)'
image

Notes:

  1. According to the error message, change 'builder.AddCosmosDbContext("myConnection");' to 'builder.AddCosmosDbContext("myConnection"; "myConnection");', the error will disappear.
    image

EXPECTED
No error shows

Metadata

Metadata

Assignees

Labels

area-integrationsIssues pertaining to Aspire Integrations packages

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions