I was investigating and en error recently with DateTime.ToString() that gave produced the following call stack:
System.FormatException: Input string was not in a correct format.
at System.DateTimeFormat.GetRealFormat(String format, DateTimeFormatInfo dtfi)
at System.DateTimeFormat.ExpandPredefinedFormat(String format, DateTime& dateTime, DateTimeFormatInfo& dtfi)
at System.DateTimeFormat.Format(DateTime dateTime, String format, DateTimeFormatInfo dtfi)
at System.DateTime.ToString(String format, IFormatProvider provider)
at MyWork.NewMethod(string a, string b)
I was doing the following…
…which is a valid input string for 2.0 and above but not 1.1. This would not have been issue but the test PC I ran the offending assembly on had both 1.1 and 2.0. The ToString() method took the path of least resistance and used the framework dependencies under 2.0 and not 1.1. Of course the real problem arises when you try to rerun the assembly on a machine that only has .NET 1.1, at this point the “o” option is invalid.
Took me a few moments to track down, and reminded me never to trust MSDN (defaults to .NET 3.x) without verifying the backward compatibility of the options.
Comments are closed.