Skip to content

Conversation

codingwithstephen
Copy link

@codingwithstephen codingwithstephen commented Jul 25, 2025

Incorrect nullability on IApiRequestFormatMetadataProvider.GetSupportedContentTypes #62405

Fix incorrect nullability in GetSupportedContentTypes

Summary of the changes:
Corrected the nullability annotations for the GetSupportedContentTypes method in the IApiRequestFormatMetadataProvider interface to match the expected behavior.

Description

This PR fixes the nullability specification on the GetSupportedContentTypes method to ensure correct usage and compatibility with nullable reference types.

Due to the requirement of a specific .NET SDK version (10.0.100-preview.7.25322.101) pinned in global.json, I have not been able to build the solution or run existing tests. Additionally, after searching the codebase, I could not find any existing unit tests covering this particular feature or method.

Screenshot 2025-07-26 at 00 19 04

Fixes #62405

@github-actions github-actions bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 25, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 25, 2025
@martincostello
Copy link
Member

This guide explains how to build the code locally: https://github.com/dotnet/aspnetcore/blob/main/docs/BuildFromSource.md

There are scripts to download the required SDK version and make it available for use in your IDE of choice.

@codingwithstephen codingwithstephen requested review from a team and tdykstra as code owners July 25, 2025 23:15
@codingwithstephen
Copy link
Author

@dotnet-policy-service agree

@codingwithstephen
Copy link
Author

@martincostello I am getting the build errors below. But I had to change these files in order for the tests to pass. What should I do here?

❌Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release, and PublicAPI.Unshipped.txt files should not be updated in release branches. See /docs/APIBaselines.md for more information.
❌Modified API baseline files:
❌src/Mvc/Mvc.Core/src/PublicAPI.Shipped.txt

@martincostello
Copy link
Member

Sorry, I don't know the answer to that specific question for this repo.

@captainsafia
Copy link
Member

@codingwithstephen Thanks for opening this PR!

We use the PublicAPI analyzers to manage API versions in our application. The analyzer is complaining because the nullability changes should be applied in the PublicApi.Unshipped.txt file in the project directory.

Are you using VS or VS Code? There should be a codefixer offered to make this change? If not, you can try implementing it manually by creating a new PublicApi.Unshipped.txt file in this directory and adding the type signature with nullability and removing the type signature without it. Something like this:

*REMOVED*Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestFormatMetadataProvider.GetSupportedContentTypes(string! contentType, System.Type! objectType) -> System.Collections.Generic.IReadOnlyList<string!>? Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestFormatMetadataProvider.GetSupportedContentTypes(string? contentType, System.Type! objectType) -> System.Collections.Generic.IReadOnlyList<string!>? 
@bkoelman
Copy link
Contributor

bkoelman commented Aug 1, 2025

@codingwithstephen I ran into the same problem. Even after installing all the bits, the fixer is unable to fix this, so you'll need to manually edit PublicAPI.Unshipped.txt, as described here.

I didn't realize this issue was already being worked on. I don't mind closing my PR if you'd like to get yours merged. Beware, though, that IApiResponseTypeMetadataProvider and OutputFormatter also need to be changed in a similar manner. See #63040.

@captainsafia
Copy link
Member

@codingwithstephen If it's alright with you, I lean towards merging @bkoelman's PR since it's a bit closer to done. If you're interested in other contributions, I'm happy to tag you on some as I work through the triage backlog. 😃

@codingwithstephen
Copy link
Author

@codingwithstephen If it's alright with you, I lean towards merging @bkoelman's PR since it's a bit closer to done. If you're interested in other contributions, I'm happy to tag you on some as I work through the triage backlog. 😃

Yes go ahead

@codingwithstephen codingwithstephen deleted the bugfix/Incorrect-nullability-on-IApiRequestFormatMetadataProvider.GetSupportedContentTypes-#62405 branch August 1, 2025 22:11
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc1 milestone Aug 1, 2025
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 community-contribution Indicates that the PR has been added by a community member

4 participants