Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Report in DefaultApiVersionReporter disposed RequestServices #1106

Open
1 task done
jacopocinaark opened this issue Aug 29, 2024 · 1 comment
Open
1 task done

Report in DefaultApiVersionReporter disposed RequestServices #1106

jacopocinaark opened this issue Aug 29, 2024 · 1 comment
Assignees

Comments

@jacopocinaark
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In my application when the HttpRequest is done the RequestServices in the HttpContext is already disposed. the Report function is called after the HttpContext is disposed so an Exception is throw (searching for ISunsetPolicyManager).
image (14)
97f253ad-250a-486e-b8fd-076b48282baf
The problem was not happening before the refactoring in Asp.Versioning package

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0

Anything else?

No response

@commonsensesoftware
Copy link
Collaborator

Something is amiss here. This is strange. There is no path where this can happen by default. I presume you are using version 6.4.x.

Minimal APIs

Versions and policies are reported as soon as the response starts because that is the time to write headers:

response.OnStarting( ReportApiVersions, (reporter, response, model) );

Controllers

Virtually the same approach is used for controllers, but it is triggered by an IActionFilter applied to an app, controller, or action:

response.OnStarting( ReportApiVersions, (reporter, response, model) );

Something strange is happening. The current HttpContext and its IServiceProvider, even scoped, should still be available at this point in time. Are you able to put together the world's simplest repro? That would help troubleshoot where things have gone wrong.

FWIW, this issue shouldn't exist in .NET 8 since ISunsetPolicyManager was added as an injected service to the constructor. This wasn't possible in .NET 6 without introducing a breaking change (which I will only do at major versions).

ISunsetPolicyManager sunsetPolicyManager,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants