KEMBAR78
[Windows] Fixed the ArgumentOutOfRangeException when setting the null to MinimumDate property in DatePicker by NanthiniMahalingam · Pull Request #30973 · dotnet/maui · GitHub
Skip to content

Conversation

NanthiniMahalingam
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details

  • Setting the MinimumDate property of the DatePicker to null results in an ArgumentOutOfRangeException.

Root Cause

  • When MinimumDate is set to null, the platform view attempts to set the CalendarDatePicker.MinDate to DateTime.MinValue. This leads to an exception because the resulting UTC time falls outside the valid range (year 0 to 10,000).

Description of Changes

  • To align with the native WinUI behavior and avoid the exception, the minimum date is now set to 100 years prior to the current date when null is specified. This ensures the value stays within a valid UTC range

Reference:
https://github.com/microsoft/microsoft-ui-xaml/blob/2aa50f0dff795cbd948588ee0e62cac7da3a396f/src/dxaml/xcp/components/DependencyObject/DependencyProperty.cpp#L253

Issues Fixed

Fixes #30922

Output

Before After
After_30922.mp4

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 1, 2025
@dotnet-policy-service
Copy link
Contributor

Hey there @@NanthiniMahalingam! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Aug 1, 2025
@NanthiniMahalingam NanthiniMahalingam changed the title Fixed the ArgumentOutOfRangeException when setting the null to MinimumDate property in DatePicker [Windows] Fixed the ArgumentOutOfRangeException when setting the null to MinimumDate property in DatePicker Aug 1, 2025
@NanthiniMahalingam NanthiniMahalingam marked this pull request as ready for review August 5, 2025 04:51
@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 04:51
@NanthiniMahalingam NanthiniMahalingam requested a review from a team as a code owner August 5, 2025 04:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an ArgumentOutOfRangeException that occurs when setting the MinimumDate property of DatePicker to null on Windows. The issue arises because the platform attempts to set DateTime.MinValue, which causes UTC conversion issues outside the valid range. The fix aligns with native WinUI behavior by setting the minimum date to 100 years prior to the current date when null is specified.

Key changes:

  • Updated DatePicker minimum date handling logic to avoid DateTime.MinValue
  • Added conditional logic to set a safe default minimum date (100 years back)
  • Added a device test to verify the fix prevents the exception

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Core/src/Platform/Windows/DatePickerExtensions.cs Updated UpdateMinimumDate method to handle null MinimumDate by setting it to 100 years back instead of DateTime.MinValue
src/Controls/tests/DeviceTests/Elements/DatePicker/DatePickerTests.Windows.cs Added test case to verify setting MinimumDate to null doesn't throw ArgumentOutOfRangeException
Comments suppressed due to low confidence (1)

src/Controls/tests/DeviceTests/Elements/DatePicker/DatePickerTests.Windows.cs:60

  • The test only verifies that no exception is thrown but doesn't validate that the MinDate is actually set to the expected value (100 years back). Consider adding an assertion to verify the platform control's MinDate property is set correctly.
		// If we reach here without exception, the test passes

@rmarinho rmarinho added this to the .NET 10.0-rc1 milestone Aug 6, 2025
@rmarinho
Copy link
Member

rmarinho commented Aug 6, 2025

/rebase

@rmarinho
Copy link
Member

rmarinho commented Aug 6, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

PureWeen commented Aug 7, 2025

  • failing tests unrelated

@PureWeen PureWeen merged commit 9deb355 into dotnet:net10.0 Aug 7, 2025
126 of 129 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants