DateOnly custom TypeConverter is ignored when using FromQuery #46384
Labels
bug
This issue describes a behavior which is not expected - a bug.
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Is there an existing issue for this?
Describe the bug
Since .NET 7 and the new support for
DateOnly
, our customTypeConverter
forDateOnly
is not invoked anymore when the controller parameter is an object initialized with[FromQuery]
on a GET requestOur client sends the date with time at zero (YYYY-MM-DDT00:00:00Z), so our converter is taking the date part and ignoring the time, which worked well in .NET 6.
In .NET 7, with exactly the same code, we have a validation error
The value '2023-01-31T00:00:00Z' is not valid.
because the new converter is taking over, and our custom is not invoked.I'm not sure whether this is a bug or us not using it properly, but it worked previously...
A workaround that don't imply changing the contract is welcome.
Expected Behavior
No behavior change.
The default TypeConverter is ignored, and our custom one is invoked.
Steps To Reproduce
The demo are the default .NET Web API template (weather forecast), which I added a simplified version of our custom TypeConverter, a global registration of it, and an object parameter to the forecast endpoint, which contains a DateOnly.
WebApplication1 is .NET 7 => with
2023-01-31T00:00:00Z
as the date parameter => TypeConverter is not invoked, validation errorWebApplication2 is .NET 6 => with
2023-01-31T00:00:00Z
=> TypeConverter is invoked, workshttps://github.com/killergege/net_typeconverter_demo
Exceptions (if any)
No response
.NET Version
7.0.102
Anything else?
Visual Studio 2022
The text was updated successfully, but these errors were encountered: