Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AspNetCore chaining UseRouting().UseEndpoints crash with InvalidOperationException #2721

Closed
Julien-Mialon opened this issue Oct 12, 2023 · 2 comments · Fixed by #2726
Closed
Labels
Bug Something isn't working

Comments

@Julien-Mialon
Copy link

Package

Sentry.AspNetCore

.NET Flavor

.NET

.NET Version

7.0.12

OS

Any (not platform specific)

SDK Version

3.40.0 & 3.40.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

Made a small repo for repro here : https://github.com/Julien-Mialon/SentryRoutingEndpointIssue/

But basically, create an AspNet API project, add Sentry, use this line of code in Startup Configure method

app.UseRouting().UseEndpoints(endpoints => endpoints.MapControllers());

And it will crash with exception :

System.InvalidOperationException: The EndpointRoutingMiddleware and EndpointMiddleware must be added to the same IApplicationBuilder instance. To use Endpoint Routing with 'Map(...)', make sure to call 'IApplicationBuilder.UseRouting' before 'IApplicationBuilder.UseEndpoints' for each branch of the middleware pipeline.

This is due to app being a SentryTracingBuilder but app.UseRouting() returning the default ApplicationBuilder which is normally wrapped in SentryTracingBuilder.

I'm not understanding every impact of this but maybe the Use method in SentryTracingBuilder should return itself in all case to avoid that ?

Expected Result

No crash

Actual Result

Exception above

@Julien-Mialon Julien-Mialon added Bug Something isn't working Platform: .NET labels Oct 12, 2023
@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 12, 2023
@bitsandfoxes
Copy link
Contributor

Hey @Julien-Mialon and thanks for raising this and providing a repro. I suspect #2602 being the culprit.

@jamescrosswell
Copy link
Collaborator

Thanks @Julien-Mialon - great catch!

I've tracked down the problem and put together a PR to resolve this. I'll put details in the PR about root cause and solution.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants