You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems the DateTime.TryParseExact method can throw a System.FormatException if the format provided is invalid. When tested in ASP.NET MVC 4.7.2, the following code:
DateTime.TryParseExact("01/10/2025", "a", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)
throws a FormatException with a stack trace:
Input string was not in a correct format
at System.DateTimeFormat.GetRealFormat(String format, DateTimeFormatInfo dtfi)
at System.DateTimeParse.ExpandPredefinedFormat(String format, DateTimeFormatInfo& dtfi, ParsingInfo& parseInfo, DateTimeResult& result)
at System.DateTimeParse.DoStrictParse(String s, String formatParam, DateTimeStyles styles, DateTimeFormatInfo dtfi, DateTimeResult& result)
at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTimeResult& result)
at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTime& result)
at System.DateTime.TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, DateTime& result)
...
Type of issue
Missing information
Description
It seems the DateTime.TryParseExact method can throw a
System.FormatException
if the format provided is invalid. When tested in ASP.NET MVC 4.7.2, the following code:DateTime.TryParseExact("01/10/2025", "a", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)
throws a
FormatException
with a stack trace:Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact?view=netframework-4.7.2#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-string()-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/DateTime.xml
Document Version Independent Id
2ba91f2f-bf41-7f7b-b0b3-64c4c0c932d9
Article author
@dotnet-bot
The text was updated successfully, but these errors were encountered: