Wednesday, February 9, 2011

Silent MessageBox.Show() Failure: Text Too Long!

I have a nifty .NET XML validation utility component in C# at work which will raise an exception if the provided XML does not conform to the provided XSD.  One of my co-workers used it, and told me that the XML file I said was invalid wasn't generating an error with that component!  Hastily testing it out, I found that it was in fact throwing an exception... but the MessageBox.Show() in the catch block wasn't doing anything!  I would trace into that statement, nothing would happen, and I'd be on the next statement.

A little paranoid googling turned this up:


It turned out there were so many errors found during the validation of the XML that the exception's message was over 900 KB, and I guess that causes a silent MessageBox.Show() failure.

...I suppose I wouldn't really like to see an error message that long, but I'd have expected MessageBox to silently truncate the message until it can be displayed.  It'd be nice if this were documented in the MSDN documentation page.  (I'm sure I've seen shortened messages appear in message boxes before.  Ah well.)