Skip to content

DateTime.Parse exception missing input value in .NET 8 #95331

Closed

Description

@LeeArbon

Description

When an incorrectly formatted string is provided to the DateTime.Parse method, a FormatException is thrown showing the invalid value, for example: "String '01/23/2023' was not recognized as a valid DateTime."

When switching to .NET 8, the exception message is missing the value between the two single quotes and so instead reads "String '' was not recognized as a valid DateTime."

Reproduction Steps

  1. Create a .NET 7 console application
  2. Add DateTime.Parse("01/23/2023", new CultureInfo("en-GB")); to Program.cs
  3. Debug the application and note the exception thrown shows the input value
  4. Change the project to .NET 8
  5. Debug the application and note the exception is now missing the value passed in and instead shows an empty value between the two single quotes

Expected behavior

The message in the FormatException should read "String '01/23/2023' was not recognized as a valid DateTime."

Actual behavior

The message in the FormatException reads "String '' was not recognized as a valid DateTime."

Regression?

This is new behaviour in .NET 8

Known Workarounds

No response

Configuration

.NET 8
Windows 11 Business
x64

Other information

No response

Activity

  1. ghost added
    needs-area-label
    on Nov 28, 2023
  2. ghost added
    untriaged
    on Nov 28, 2023
  3. stephentoub commented on Nov 28, 2023

    @stephentoub
    Member

    @tarekgh, yet another report. We should backport the fix, assuming this is indeed the same issue.

  4. added and removed
    needs-area-label
    on Nov 28, 2023
  5. karakasa commented on Nov 28, 2023

    @karakasa
    Contributor

    Probably fixed in #91303

  6. tarekgh commented on Nov 28, 2023

    @tarekgh
    Member

    yet another report. We should backport the fix, assuming this is indeed the same issue.

    I'll take a look and will work on fixing and porting the fix to 8.0 servicing.

  7. added this to the 8.0.x milestone on Nov 28, 2023
  8. ghost removed
    untriaged
    on Nov 28, 2023
  9. self-assigned this
    on Nov 28, 2023
  10. tarekgh commented on Nov 28, 2023

    @tarekgh
    Member
  11. ghost added
    in-pr
    on Nov 28, 2023
  12. ghost removed
    in-pr
    on Nov 30, 2023
  13. tarekgh commented on Nov 30, 2023

    @tarekgh
    Member

    Fixed by the attached PR.

  14. locked and limited conversation to collaborators on Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions