question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware skipped when UseEndpoints is called multiple times

See original GitHub issue

Describe the bug

Middleware between two calls to configure endpoint routing using app.UseEndpoints(...) is never executed.

Expected: Looking at this startup code, I would expect SetUser() middleware to be executed before MVC controller. image

Actual: The breakpoint is never hit.

To Reproduce

Create a new ASP.NET Core 3.1 MVC web application. Replace Startup.cs with this: https://gist.github.com/jussimattila/047ab4936f943ed8b0f2a6574c2525a5

Set a breakpoint to the middleware, confirm it is not executed.

Further technical details

  • ASP.NET Core 3.1
C:\Users\Jussi>dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.100
 Commit:    cd82f021f4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db
  • Visual Studio 2019 16.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rizicommented, May 8, 2020

@mkArtakMSFT we have exactly the same problem, please “allow” to call app.UseEndPoints multiple times and execute all configured middlewares. br

1reaction
khellangcommented, Apr 23, 2020

@mkArtakMSFT This issue isn’t a question or a discussion. This is a bug 🐛 🙈

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is middleware not executed when there are multiple ...
So yes, you can use UseEndpoints(…) multiple times but it will likely not do what you expect it to do. All configuration delegates...
Read more >
Why is middleware not executed when there are multiple calls ...
So yes, you can use UseEndpoints(…) multiple times but it will likely not do what you expect it to do. All configuration delegates...
Read more >
Routing in ASP.NET Core
The UseEndpoints middleware is terminal when a match is found. Terminal middleware is defined later in this article.
Read more >
MVC1005: Cannot use UseMvc with Endpoint Routing
Using MVC via UseMvc or UseMvcWithDefaultRoute requires an explicit opt-in inside Startup.ConfigureServices . This is required because MVC ...
Read more >
ASP.NET Core Middleware Components
ASP.NET Core Middleware Components are components that are used to handle the HTTP Request and Response in .NET Core application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found