Skip to content

Conversation

@captainsafia
Copy link
Member

This PR resolves an issue where an IOptionsSnapshot<> instance was incorrectly resolved from the root provider. It also updates the tests for OpenApiDocumentProvider to validate scopes so we can catch this issue in tests.

@captainsafia captainsafia requested a review from a team as a code owner October 8, 2024 23:59
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Oct 8, 2024
Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this customer reported?

@eerhardt
Copy link
Member

eerhardt commented Oct 9, 2024

Was this customer reported?

Do I count as a customer? 😆

I was getting an exception in dotnet/eshop that I showed @captainsafia and she knew what the problem was.

@captainsafia captainsafia merged commit cf0b8a5 into main Oct 9, 2024
27 checks passed
@captainsafia captainsafia deleted the safia/scoped-service-provider branch October 9, 2024 15:41
@captainsafia
Copy link
Member Author

/backport to release/9.0

@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Oct 9, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2024

Started backporting to release/9.0: https://github.com/dotnet/aspnetcore/actions/runs/11258408430

@epsitec
Copy link

epsitec commented Nov 28, 2024

I am experiencing crashes when using OpenApi. The code responsible for the crash is in OpenApiDocumentProvider, when it calls GetRequiredService<IOptionsSnapshot<OpenApiOptions>>(). Apparently, this has been fixed:

var options = serviceProvider.GetRequiredService<IOptionsMonitor<OpenApiOptions>>();

and should have been backported to 9.0 if I interpret this pull request correctly.

However, in the NuGet package version 9.0.0 available online, the fix is missing!?
Any chance you, @captainsafia could have a look at this?

Here is a screenshot of what I am seeing:

image

@martincostello
Copy link
Member

Based on #58320 (comment), the fix wasn't actually backported as it was thought to be practically impossible.

If you're seeing it in .NET 9.0.0, then maybe not.

@epsitec
Copy link

epsitec commented Nov 28, 2024

So I will review my code and try to understand what I am doing, which triggers this impossible situation.

captainsafia added a commit that referenced this pull request Dec 31, 2024
* Validate scopes in OpenApiDocumentProvider tests and fix scope

* Use IOptionsMonitor to resolve OpenApiOptions
captainsafia added a commit that referenced this pull request Feb 11, 2025
* Validate scopes in OpenApiDocumentProvider tests and fix scope

* Use IOptionsMonitor to resolve OpenApiOptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants