Skip to content

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

@LeeArbon

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions