String.Format and Input string was not in a correct format Error
I ran into (another) interesting error today when using String.Format1. I was getting the error message "Input string was not in a correct format.". In this instance I was calling the content from an XML file, the data was wrapped in CDATA tags so there shouldn't have been an issue with line breaks etc. On investigating the error further I found it was being caused because the content was a HTML page. More specifically, the String.Format error "Input string was not in a correct format." was being caused by the CSS declaration's curly braces.
To work around the method perceiving them as placeholders, simply replace each curly brace "{" with double braces "{{".
To replicate the error:
The fix in place:
1The String.Format method accepts a format string which can include place holders (designated by the curly braces {} and a number that refers to the location of the item that should appear in the list). A quick example of String.Format:
Would produce: "This is some text the date is 02/10/2006"
Liked this post? Got a suggestion? Leave a comment