Search code examples
c#asp.net-core

How do I resolve "Request reached the end of the middleware pipeline without being handled by application code."?


I am attempting to convert our public API into using just the single Program.cs format as part of our .NET8 update but despite the application building and running, when I try to hit a route I get a 404 and in the debug output I get "Request reached the end of the middleware pipeline without being handled by application code." I have stripped out all but the default "app.Xyz" that come with the dotnet template but the issue still remains. My "app" section of the Program.cs now looks like this:

var app = builder.Build();

var listener = app.Services.GetRequiredService<DiagnosticListener>();
var observer = ActivatorUtilities.CreateInstance<AnalysisDiagnosticAdapter>(app.Services);
using var disposable = listener.SubscribeWithAdapter(observer);


app.UseHttpsRedirection();
app.UseRouting();
app.UseUserAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
    name: "Default",
    pattern:"{controller=Home}/{action=Index}/{id?}"
    );

app.Run();

I added in the DiagnosticAdapter to see if that would help but it doesn't really tell me anything that the default debug output did.

I can add a test route in this file, using app.MapGet(); which works and returns correctly but any controller external to this return the 404 error.


Solution

  • I stumbled on the solution by chance. I had a rogue using System.Web.Http; statement in one of my classes. Not really sure why it was building and running with just a warning when removing it seemed to make everything work just fine.

    I forgot to include the link that pointed me in the right direction: StackOverflow System.Web.Http not supported in .NET6