From 9c26f24a4cc8746470214ac1ecb5249da032ad52 Mon Sep 17 00:00:00 2001 From: stephen_mooney Date: Fri, 25 Jul 2025 22:56:10 +0100 Subject: [PATCH 1/4] Incorrect nullability on IApiRequestFormatMetadataProvider.GetSupportedContentTypes #62405 --- .../Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs | 2 +- src/Middleware/HttpLogging/src/MediaTypeOptions.cs | 4 ++-- src/Mvc/Mvc.Core/src/ConsumesAttribute.cs | 4 ++-- src/Mvc/Mvc.Core/src/FileResult.cs | 2 +- src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs | 4 ++-- src/Mvc/Mvc.Core/src/ProducesAttribute.cs | 2 +- src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs b/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs index 5f177b2afecc..30903569a92b 100644 --- a/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs +++ b/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs @@ -1103,7 +1103,7 @@ class FromRoute : Attribute, IFromRouteMetadata class TestConsumesAttribute : Attribute, IAcceptsMetadata { - public TestConsumesAttribute(Type requestType, string contentType, params string[] otherContentTypes) + public TestConsumesAttribute(Type requestType, string? contentType, params string[] otherContentTypes) { ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Middleware/HttpLogging/src/MediaTypeOptions.cs b/src/Middleware/HttpLogging/src/MediaTypeOptions.cs index 48aa9deefe37..00143885f1e6 100644 --- a/src/Middleware/HttpLogging/src/MediaTypeOptions.cs +++ b/src/Middleware/HttpLogging/src/MediaTypeOptions.cs @@ -47,7 +47,7 @@ internal void AddText(MediaTypeHeaderValue mediaType) /// If charset is not specified in the contentType, the encoding will default to UTF-8. /// /// The content type to add. - public void AddText(string contentType) + public void AddText(string? contentType) { ArgumentNullException.ThrowIfNull(contentType); @@ -59,7 +59,7 @@ public void AddText(string contentType) /// /// The content type to add. /// The encoding to use. - public void AddText(string contentType, Encoding encoding) + public void AddText(string? contentType, Encoding encoding) { ArgumentNullException.ThrowIfNull(contentType); ArgumentNullException.ThrowIfNull(encoding); diff --git a/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs b/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs index db60690d461a..68ce768b0962 100644 --- a/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs +++ b/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs @@ -36,7 +36,7 @@ public class ConsumesAttribute : /// The request content type. /// The additional list of allowed request content types. /// - public ConsumesAttribute(string contentType, params string[] otherContentTypes) + public ConsumesAttribute(string? contentType, params string[] otherContentTypes) { ArgumentNullException.ThrowIfNull(contentType); @@ -59,7 +59,7 @@ public ConsumesAttribute(string contentType, params string[] otherContentTypes) /// The request content type. /// The additional list of allowed request content types. /// - public ConsumesAttribute(Type requestType, string contentType, params string[] otherContentTypes) + public ConsumesAttribute(Type requestType, string? contentType, params string[] otherContentTypes) { ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Mvc/Mvc.Core/src/FileResult.cs b/src/Mvc/Mvc.Core/src/FileResult.cs index cf946444d3c4..dab9bebf9c72 100644 --- a/src/Mvc/Mvc.Core/src/FileResult.cs +++ b/src/Mvc/Mvc.Core/src/FileResult.cs @@ -19,7 +19,7 @@ public abstract class FileResult : ActionResult /// the provided . /// /// The Content-Type header of the response. - protected FileResult(string contentType) + protected FileResult(string? contentType) { ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs b/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs index 57d5a4b555c8..18201533c951 100644 --- a/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs +++ b/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs @@ -21,7 +21,7 @@ public class FormatterMappings /// /// The format value. /// The media type for the format value. - public void SetMediaTypeMappingForFormat(string format, string contentType) + public void SetMediaTypeMappingForFormat(string format, string? contentType) { ArgumentNullException.ThrowIfNull(format); ArgumentNullException.ThrowIfNull(contentType); @@ -35,7 +35,7 @@ public void SetMediaTypeMappingForFormat(string format, string contentType) /// /// The format value. /// The media type for the format value. - public void SetMediaTypeMappingForFormat(string format, MediaTypeHeaderValue contentType) + public void SetMediaTypeMappingForFormat(string format, MediaTypeHeaderValue? contentType) { ArgumentNullException.ThrowIfNull(format); ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Mvc/Mvc.Core/src/ProducesAttribute.cs b/src/Mvc/Mvc.Core/src/ProducesAttribute.cs index bcef087a2e6a..6a45015266da 100644 --- a/src/Mvc/Mvc.Core/src/ProducesAttribute.cs +++ b/src/Mvc/Mvc.Core/src/ProducesAttribute.cs @@ -33,7 +33,7 @@ public ProducesAttribute(Type type) /// /// The allowed content type for a response. /// Additional allowed content types for a response. - public ProducesAttribute(string contentType, params string[] additionalContentTypes) + public ProducesAttribute(string? contentType, params string[] additionalContentTypes) { ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs b/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs index f9c55192040e..66d7e36ac270 100644 --- a/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs +++ b/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs @@ -45,7 +45,7 @@ public ProducesResponseTypeAttribute(Type type, int statusCode) /// The HTTP response status code. /// The content type associated with the response. /// Additional content types supported by the response. - public ProducesResponseTypeAttribute(Type type, int statusCode, string contentType, params string[] additionalContentTypes) + public ProducesResponseTypeAttribute(Type type, int statusCode, string? contentType, params string[] additionalContentTypes) { ArgumentNullException.ThrowIfNull(contentType); From b45a0e43e790d1db5a22216d6bbdbbd053bc4adc Mon Sep 17 00:00:00 2001 From: stephen_mooney Date: Fri, 25 Jul 2025 23:41:00 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Incorrect=20nullability=20on=20IApiRequestF?= =?UTF-8?q?ormatMetadataProvider.GetSupport=E2=80=A6=20#62935?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs | 2 +- src/Middleware/HttpLogging/src/MediaTypeOptions.cs | 4 ++-- src/Mvc/Mvc.Core/src/ConsumesAttribute.cs | 4 ++-- src/Mvc/Mvc.Core/src/FileResult.cs | 2 +- src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs | 4 ++-- src/Mvc/Mvc.Core/src/Formatters/InputFormatter.cs | 2 +- src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs b/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs index 30903569a92b..5f177b2afecc 100644 --- a/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs +++ b/src/Http/Routing/test/UnitTests/Builder/RouteHandlerEndpointRouteBuilderExtensionsTest.cs @@ -1103,7 +1103,7 @@ class FromRoute : Attribute, IFromRouteMetadata class TestConsumesAttribute : Attribute, IAcceptsMetadata { - public TestConsumesAttribute(Type requestType, string? contentType, params string[] otherContentTypes) + public TestConsumesAttribute(Type requestType, string contentType, params string[] otherContentTypes) { ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Middleware/HttpLogging/src/MediaTypeOptions.cs b/src/Middleware/HttpLogging/src/MediaTypeOptions.cs index 00143885f1e6..48aa9deefe37 100644 --- a/src/Middleware/HttpLogging/src/MediaTypeOptions.cs +++ b/src/Middleware/HttpLogging/src/MediaTypeOptions.cs @@ -47,7 +47,7 @@ internal void AddText(MediaTypeHeaderValue mediaType) /// If charset is not specified in the contentType, the encoding will default to UTF-8. /// /// The content type to add. - public void AddText(string? contentType) + public void AddText(string contentType) { ArgumentNullException.ThrowIfNull(contentType); @@ -59,7 +59,7 @@ public void AddText(string? contentType) /// /// The content type to add. /// The encoding to use. - public void AddText(string? contentType, Encoding encoding) + public void AddText(string contentType, Encoding encoding) { ArgumentNullException.ThrowIfNull(contentType); ArgumentNullException.ThrowIfNull(encoding); diff --git a/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs b/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs index 68ce768b0962..db60690d461a 100644 --- a/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs +++ b/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs @@ -36,7 +36,7 @@ public class ConsumesAttribute : /// The request content type. /// The additional list of allowed request content types. /// - public ConsumesAttribute(string? contentType, params string[] otherContentTypes) + public ConsumesAttribute(string contentType, params string[] otherContentTypes) { ArgumentNullException.ThrowIfNull(contentType); @@ -59,7 +59,7 @@ public ConsumesAttribute(string? contentType, params string[] otherContentTypes) /// The request content type. /// The additional list of allowed request content types. /// - public ConsumesAttribute(Type requestType, string? contentType, params string[] otherContentTypes) + public ConsumesAttribute(Type requestType, string contentType, params string[] otherContentTypes) { ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Mvc/Mvc.Core/src/FileResult.cs b/src/Mvc/Mvc.Core/src/FileResult.cs index dab9bebf9c72..cf946444d3c4 100644 --- a/src/Mvc/Mvc.Core/src/FileResult.cs +++ b/src/Mvc/Mvc.Core/src/FileResult.cs @@ -19,7 +19,7 @@ public abstract class FileResult : ActionResult /// the provided . /// /// The Content-Type header of the response. - protected FileResult(string? contentType) + protected FileResult(string contentType) { ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs b/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs index 18201533c951..57d5a4b555c8 100644 --- a/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs +++ b/src/Mvc/Mvc.Core/src/Formatters/FormatterMappings.cs @@ -21,7 +21,7 @@ public class FormatterMappings /// /// The format value. /// The media type for the format value. - public void SetMediaTypeMappingForFormat(string format, string? contentType) + public void SetMediaTypeMappingForFormat(string format, string contentType) { ArgumentNullException.ThrowIfNull(format); ArgumentNullException.ThrowIfNull(contentType); @@ -35,7 +35,7 @@ public void SetMediaTypeMappingForFormat(string format, string? contentType) /// /// The format value. /// The media type for the format value. - public void SetMediaTypeMappingForFormat(string format, MediaTypeHeaderValue? contentType) + public void SetMediaTypeMappingForFormat(string format, MediaTypeHeaderValue contentType) { ArgumentNullException.ThrowIfNull(format); ArgumentNullException.ThrowIfNull(contentType); diff --git a/src/Mvc/Mvc.Core/src/Formatters/InputFormatter.cs b/src/Mvc/Mvc.Core/src/Formatters/InputFormatter.cs index 2474e63ab177..47a6fa1b5b27 100644 --- a/src/Mvc/Mvc.Core/src/Formatters/InputFormatter.cs +++ b/src/Mvc/Mvc.Core/src/Formatters/InputFormatter.cs @@ -118,7 +118,7 @@ public virtual Task ReadAsync(InputFormatterContext contex public abstract Task ReadRequestBodyAsync(InputFormatterContext context); /// - public virtual IReadOnlyList? GetSupportedContentTypes(string contentType, Type objectType) + public virtual IReadOnlyList? GetSupportedContentTypes(string? contentType, Type objectType) { if (SupportedMediaTypes.Count == 0) { diff --git a/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs b/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs index 66d7e36ac270..f9c55192040e 100644 --- a/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs +++ b/src/Mvc/Mvc.Core/src/ProducesResponseTypeAttribute.cs @@ -45,7 +45,7 @@ public ProducesResponseTypeAttribute(Type type, int statusCode) /// The HTTP response status code. /// The content type associated with the response. /// Additional content types supported by the response. - public ProducesResponseTypeAttribute(Type type, int statusCode, string? contentType, params string[] additionalContentTypes) + public ProducesResponseTypeAttribute(Type type, int statusCode, string contentType, params string[] additionalContentTypes) { ArgumentNullException.ThrowIfNull(contentType); From 1c95dbc846dc813437cd95cce9ae6a3aa57f94c0 Mon Sep 17 00:00:00 2001 From: stephen_mooney Date: Fri, 25 Jul 2025 23:42:52 +0100 Subject: [PATCH 3/4] https://github.com/dotnet/aspnetcore/issues/62405 --- src/Mvc/Mvc.Core/src/ProducesAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mvc/Mvc.Core/src/ProducesAttribute.cs b/src/Mvc/Mvc.Core/src/ProducesAttribute.cs index 6a45015266da..bcef087a2e6a 100644 --- a/src/Mvc/Mvc.Core/src/ProducesAttribute.cs +++ b/src/Mvc/Mvc.Core/src/ProducesAttribute.cs @@ -33,7 +33,7 @@ public ProducesAttribute(Type type) /// /// The allowed content type for a response. /// Additional allowed content types for a response. - public ProducesAttribute(string? contentType, params string[] additionalContentTypes) + public ProducesAttribute(string contentType, params string[] additionalContentTypes) { ArgumentNullException.ThrowIfNull(contentType); From b05f9babce52033cb8ddb5e0730fc153fc97bf8a Mon Sep 17 00:00:00 2001 From: stephen_mooney Date: Sat, 26 Jul 2025 00:15:14 +0100 Subject: [PATCH 4/4] Incorrect nullability on IApiRequestFormatMetadataProvider.GetSupportedContentTypes #62405 - update public api --- .../src/ApiExplorer/IApiRequestFormatMetadataProvider.cs | 2 +- src/Mvc/Mvc.Core/src/PublicAPI.Shipped.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mvc/Mvc.Core/src/ApiExplorer/IApiRequestFormatMetadataProvider.cs b/src/Mvc/Mvc.Core/src/ApiExplorer/IApiRequestFormatMetadataProvider.cs index cfb942053215..50e84006030d 100644 --- a/src/Mvc/Mvc.Core/src/ApiExplorer/IApiRequestFormatMetadataProvider.cs +++ b/src/Mvc/Mvc.Core/src/ApiExplorer/IApiRequestFormatMetadataProvider.cs @@ -25,6 +25,6 @@ public interface IApiRequestFormatMetadataProvider /// /// Content types which are supported by the . IReadOnlyList? GetSupportedContentTypes( - string contentType, + string? contentType, Type objectType); } diff --git a/src/Mvc/Mvc.Core/src/PublicAPI.Shipped.txt b/src/Mvc/Mvc.Core/src/PublicAPI.Shipped.txt index ebb18238569f..824fa9ceec9d 100644 --- a/src/Mvc/Mvc.Core/src/PublicAPI.Shipped.txt +++ b/src/Mvc/Mvc.Core/src/PublicAPI.Shipped.txt @@ -172,7 +172,7 @@ Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionGroupNameProvider.GroupName. Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionVisibilityProvider Microsoft.AspNetCore.Mvc.ApiExplorer.IApiDescriptionVisibilityProvider.IgnoreApi.get -> bool Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestFormatMetadataProvider -Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestFormatMetadataProvider.GetSupportedContentTypes(string! contentType, System.Type! objectType) -> System.Collections.Generic.IReadOnlyList? +Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestFormatMetadataProvider.GetSupportedContentTypes(string? contentType, System.Type! objectType) -> System.Collections.Generic.IReadOnlyList? Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestMetadataProvider Microsoft.AspNetCore.Mvc.ApiExplorer.IApiRequestMetadataProvider.SetContentTypes(Microsoft.AspNetCore.Mvc.Formatters.MediaTypeCollection! contentTypes) -> void Microsoft.AspNetCore.Mvc.ApiExplorer.IApiResponseMetadataProvider @@ -2454,7 +2454,7 @@ virtual Microsoft.AspNetCore.Mvc.Formatters.FormatFilter.GetFormat(Microsoft.Asp virtual Microsoft.AspNetCore.Mvc.Formatters.InputFormatter.CanRead(Microsoft.AspNetCore.Mvc.Formatters.InputFormatterContext! context) -> bool virtual Microsoft.AspNetCore.Mvc.Formatters.InputFormatter.CanReadType(System.Type! type) -> bool virtual Microsoft.AspNetCore.Mvc.Formatters.InputFormatter.GetDefaultValueForType(System.Type! modelType) -> object? -virtual Microsoft.AspNetCore.Mvc.Formatters.InputFormatter.GetSupportedContentTypes(string! contentType, System.Type! objectType) -> System.Collections.Generic.IReadOnlyList? +virtual Microsoft.AspNetCore.Mvc.Formatters.InputFormatter.GetSupportedContentTypes(string? contentType, System.Type! objectType) -> System.Collections.Generic.IReadOnlyList? virtual Microsoft.AspNetCore.Mvc.Formatters.InputFormatter.ReadAsync(Microsoft.AspNetCore.Mvc.Formatters.InputFormatterContext! context) -> System.Threading.Tasks.Task! virtual Microsoft.AspNetCore.Mvc.Formatters.OutputFormatter.CanWriteResult(Microsoft.AspNetCore.Mvc.Formatters.OutputFormatterCanWriteContext! context) -> bool virtual Microsoft.AspNetCore.Mvc.Formatters.OutputFormatter.CanWriteType(System.Type? type) -> bool