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.

[Analyzer] Detect adding middleware services but middleware isn't used

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Developers can add the services for middleware, e.g. AddCors, and not realize that the middleware needs to be registered in middleware with UseCors. There is no error or indication to the developer about what they’re missing.

Describe the solution you’d like

An analyzer that looks at what middleware services are registered, what middleware is used in request pipeline, and warns the developer about middleware that’s unused.

We can’t infer what these names are so we’d hard code AddMiddleware and UseMiddleware method names.

Additional context

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
davidfowlcommented, Sep 29, 2022

Yes this is the only analyzer suggestion I think shouldn’t be a warning by default. People will refactor things into methods and the analyzer will get confused quickly.

0reactions
msftbot[bot]commented, Sep 30, 2022

Thanks for contacting us.

We’re moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it’s very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Analyzer] Detect middleware in pipeline after terminal ...
(maybe) Detect terminal middleware with WebApplication . Warn the developer they may need to add UseEndpoints before terminal middleware.
Read more >
c# - Confirm that middleware is in use
I am trying to confirm via a unit test that middleware is actually being added to the pipeline. I have the following static...
Read more >
ASP.NET Core Middleware
Learn about ASP.NET Core middleware and the request pipeline. ... Middleware code analysis; Create a middleware pipeline with WebApplication ...
Read more >
Understanding your middleware pipeline with the ...
Analysing your middleware pipeline · 1. Add the required packages · 2. Creating a diagnostic adapter · 3. Add the necessary services.
Read more >
ASP.NET Core middleware with Roslyn Analyzers - Part 1
Learn how to create Roslyn Analyzers to help add ASP.NET Core middleware in the right order. In this post, I'll show you how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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