Skip to content

.NET 6 API Example Failing with Middleware Order Issue #46

@TimCorey

Description

@TimCorey

I set up a basic example of a .NET 6 Web API with just WatchDog installed. When I try to run the application, I get the following message:

System.InvalidOperationException
HResult=0x80131509
Message=EndpointRoutingMiddleware matches endpoints setup by EndpointMiddleware and so must be added to the request execution pipeline before EndpointMiddleware. Please add EndpointRoutingMiddleware by calling 'IApplicationBuilder.UseRouting' inside the call to 'Configure(...)' in the application startup code.

I have tested it on the example code, and I get a similar error. Here is the code from my Program.cs file:

using WatchDog;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddWatchDogServices();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseWatchDogExceptionLogger();

app.UseWatchDog(opts =>
{
    opts.WatchPageUsername = "admin";
    opts.WatchPagePassword = "admin";
});

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

The error occurs on the app.UseWatchDog line.

Is there something I am missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions