maximum string length for MessageBox.Show()

  • Thread starter Thread starter molafish
  • Start date Start date
M

molafish

I have discovered an upper limit to the size of a string for the Show
() method. It appears that if the string is beyond the limit, the Show
() method fails silently by not showing the messagebox at all. This is
reproducable in the debugger and outside of it (inside the debugger,
the sql string's contents are inspectable, but the message box does
not show).

Here's the code to reproduce it, in a fresh VB.NET solution (VS 2005):
Dim sql As String = My.Computer.FileSystem.ReadAllText
(Application.StartupPath & "\update\update.sql")
MessageBox.Show(sql)

The upper limit appears to be 260,087 bytes for the file. When those
260,087 bytes are entered into a String object, it grows to 18 + (2 *
260087) = 520192. Because the sql object is >85,000 bytes, it's
allocated on the Lagrge Object Heap. At the time I had 95mb of free
memory, 320mb in the system cache, and 1.5gb available through paging.

I suppose I will submit a bug report unless anybody here has an
explanation for why Show() is silently failing. I could check the size
of the string before I show() it, but I would think that Show() should
throw an exception if its input is too large.
 
I have discovered an upper limit to the size of a string for the Show
() method. It appears that if the string is beyond the limit, the Show
() method fails silently by not showing the messagebox at all. This is
reproducable in the debugger and outside of it (inside the debugger,
the sql string's contents are inspectable, but the message box does
not show).

Here's the code to reproduce it, in a fresh VB.NET solution (VS 2005):
Dim sql As String = My.Computer.FileSystem.ReadAllText
(Application.StartupPath & "\update\update.sql")
MessageBox.Show(sql)

The upper limit appears to be 260,087 bytes for the file. When those
260,087 bytes are entered into a String object, it grows to 18 + (2 *
260087) = 520192. Because the sql object is >85,000 bytes, it's
allocated on the Lagrge Object Heap. At the time I had 95mb of free
memory, 320mb in the system cache, and 1.5gb available through paging.

I suppose I will submit a bug report unless anybody here has an
explanation for why Show() is silently failing. I could check the size
of the string before I show() it, but I would think that Show() should
throw an exception if its input is too large.


Though it may be an issue worth reporting, I don't think you should expect
to use a MessageBox for a string that long. The largest screen I have is
1900x1200 pixels. If a character is 8x8, that gives only enough room for
35625 characters. Anything more than one or two sentences should
probrobably migrate to a text box on a custom form with scroll bars, in my
opinion.
 
Though it may be an issue worth reporting, I don't think you should expect
to use a MessageBox for a string that long.  The largest screen I have is
1900x1200 pixels.  If a character is 8x8, that gives only enough room for
35625 characters.  Anything more than one or two sentences should
probrobably migrate to a text box on a custom form with scroll bars, in my
opinion.

Agreed. It wasn't my intention to use the messagebox in this manner.
It just so happened that I had to use messageboxes for debugging in
lieu of breakpoints in this particular instance, and so I noticed this.
 
Back
Top