SharePoint’s Way of Saying Your String is Too Long

I accidentally defined a field in a SharePoint list as a text field instead of a multiline text field and when I went to save a very long XML string into that field I received the following message:

Invalid text value. A text field contains invalid data. Please check the value and try again.

Since this was XML my developer brain immediately began thinking about which part of the XML was mangled and how that was happening.  After about 10 minutes of looking through the XML generation I stopped and wondering why the heck SharePoint was even parsing my XML.  And then it dawned on me that it wasn’t and that there was some other problem.  So, long story short, if you see this message it may simply mean that your string is too long.

To be fair, the UI gives you a much better error, but I was updating the list item programmatically.  It really would be nice, however, if the error message was more accurate.  Hint, hint, Microsoft.

NOTE: this error is fairly generic and does not ALWAYS mean that your string is too long.