I started a basic Blazor Server App project and added Cosmos DB support and a single model Blueprint.
When running a simple fetch on my Cosmos DB, I get an error where I need some guidance on how to troubleshoot that.
Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: 34b01955-94e6-4dc5-bb90-dd865b8dcdbf; Reason: (Message: {"Errors":["Resource Not Found. Learn more: https:\/\/aka.ms\/cosmosdb-tsg-not-found"]}
Find the complete stack trace further down.
Include your code
Program.cs
I'm using a local secrets.json and I can confirm that variable builder.Configuration["FactorioStudioContext"] contains the correct configuration string.
using FactorioStudio.Data;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.EntityFrameworkCore;
using Microsoft.Identity.Web;
using Microsoft.Identity.Web.UI;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddDbContext<FactorioStudioContext>(options =>
options.UseCosmos(builder.Configuration["FactorioStudioContext"], databaseName: "FactorioStudio"));
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));
builder.Services.AddControllersWithViews()
.AddMicrosoftIdentityUI();
// ...
Data\FactorioStudioContext.cs
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
namespace FactorioStudio.Data;
public class FactorioStudioContext : DbContext
{
public FactorioStudioContext(DbContextOptions<FactorioStudioContext> options) : base(options)
{
}
public DbSet<Blueprint> Blueprints { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blueprint>()
.ToContainer("Blueprints")
.HasPartitionKey(o => o.Id)
.UseETagConcurrency();
base.OnModelCreating(modelBuilder);
}
}
Data\Blueprint.cs
namespace FactorioStudio.Data;
public class Blueprint
{
public Guid Id { get; set; }
public string Name { get; set; }
}
Pages\Blueprints\Index.cshtml.cs (Scaffolded via VS2022)
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using FactorioStudio.Data;
namespace FactorioStudio.Pages.Blueprints;
public class IndexModel : PageModel
{
private readonly FactorioStudioContext _context;
public IndexModel(FactorioStudioContext context)
{
_context = context;
}
public IList<Blueprint> Blueprint { get;set; } = default!;
public async Task OnGetAsync()
{
if (_context.Blueprints != null)
{
Blueprint = await _context.Blueprints.ToListAsync();
}
}
}
My Cosmos DB database is named "FactorioStudio" (see also Program.cs) and the container is named "FactorioStudioContext" (using the name derived from the DbContext class that is used by default by efcore).
Ask a question
I started a basic Blazor Server App project and added Cosmos DB support and a single model
Blueprint
. When running a simple fetch on my Cosmos DB, I get an error where I need some guidance on how to troubleshoot that.Find the complete stack trace further down.
Include your code
Program.cs
I'm using a local secrets.json and I can confirm that variable
builder.Configuration["FactorioStudioContext"]
contains the correct configuration string.Data\FactorioStudioContext.cs
Data\Blueprint.cs
Pages\Blueprints\Index.cshtml.cs (Scaffolded via VS2022)
My Cosmos DB database is named "FactorioStudio" (see also
Program.cs
) and the container is named "FactorioStudioContext" (using the name derived from the DbContext class that is used by default by efcore).Include stack traces
Include verbose output
Include provider and version information
EF Core version: 7.0.4 Database provider: Microsoft.EntityFrameworkCore.Cosmos Target framework: .NET 7.0 Operating system: Windows 11 IDE: Visual Studio 2022 17.5