WPF MessageBox is not displayed at all if long message is passed
up vote
0
down vote
favorite
I ran into situation when some MessageBoxes with error messages were not displayed at all. After closer investigation, I was able to narrow down the problem to cases when a very long string is passed as messageBoxText
.
In such cases, call MessageBox.Show
does not display anything, returns MessageBoxResult.No
and, in most cases, there's a message in the Output
window saying The thread 0xHEXNUMBER has exited with code 0 (0x0)
. For me, this method silently fails.
This is very strange - WPF is a very mature technology and I expect this code to work according to spec or throw some exception (e.g. OutOfMemory, StackOverflowException). I've debugged the program and no manged or unmanged exceptions are thrown and caught.
What is the root cause of MessageBox not being displayed? Is there some easy way to debug such things (since no exceptions are thrown or logged). What is the messageBoxText length limit and what does it depend on (I could check that empirically on my computer, but would be conclusive for one OS/platform/.NET Framework version at best)?
Repro:
Here's a code which demonstrates the problem (it can be used with standard WPF Application template in Visual Studio).
MainWindow.xaml:
<Window x:Class="LongMessageInMessageBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Click="ShortMessage_Clicked">Short Message</Button>
<Button Grid.Row="1" Grid.Column="0" Click="LongMessage_Clicked">Long Message</Button>
</Grid>
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LongMessageInMessageBox
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
/// Method which shows that displaying short message works correctly
private void ShortMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("ShortMessage_Clicked");
var result = MessageBox.Show("Short Message");
Console.WriteLine(result);
/// Method which shows that displaying a long message does not work
private void LongMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("LongMessage_Clicked");
var longTextBuilder = new System.Text.StringBuilder(10000);
longTextBuilder.Append("Long Message n");
for (int i = 1; i <= 100000; i++)
longTextBuilder.Append(" ").Append(i);
var result = MessageBox.Show(longTextBuilder.ToString());
Console.WriteLine(result);
Sample from Output
window:
ShortMessage_Clicked
OK
ShortMessage_Clicked
OK
LongMessage_Clicked
No
The thread 0x55bc has exited with code 0 (0x0).
wpf messagebox
add a comment |
up vote
0
down vote
favorite
I ran into situation when some MessageBoxes with error messages were not displayed at all. After closer investigation, I was able to narrow down the problem to cases when a very long string is passed as messageBoxText
.
In such cases, call MessageBox.Show
does not display anything, returns MessageBoxResult.No
and, in most cases, there's a message in the Output
window saying The thread 0xHEXNUMBER has exited with code 0 (0x0)
. For me, this method silently fails.
This is very strange - WPF is a very mature technology and I expect this code to work according to spec or throw some exception (e.g. OutOfMemory, StackOverflowException). I've debugged the program and no manged or unmanged exceptions are thrown and caught.
What is the root cause of MessageBox not being displayed? Is there some easy way to debug such things (since no exceptions are thrown or logged). What is the messageBoxText length limit and what does it depend on (I could check that empirically on my computer, but would be conclusive for one OS/platform/.NET Framework version at best)?
Repro:
Here's a code which demonstrates the problem (it can be used with standard WPF Application template in Visual Studio).
MainWindow.xaml:
<Window x:Class="LongMessageInMessageBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Click="ShortMessage_Clicked">Short Message</Button>
<Button Grid.Row="1" Grid.Column="0" Click="LongMessage_Clicked">Long Message</Button>
</Grid>
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LongMessageInMessageBox
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
/// Method which shows that displaying short message works correctly
private void ShortMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("ShortMessage_Clicked");
var result = MessageBox.Show("Short Message");
Console.WriteLine(result);
/// Method which shows that displaying a long message does not work
private void LongMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("LongMessage_Clicked");
var longTextBuilder = new System.Text.StringBuilder(10000);
longTextBuilder.Append("Long Message n");
for (int i = 1; i <= 100000; i++)
longTextBuilder.Append(" ").Append(i);
var result = MessageBox.Show(longTextBuilder.ToString());
Console.WriteLine(result);
Sample from Output
window:
ShortMessage_Clicked
OK
ShortMessage_Clicked
OK
LongMessage_Clicked
No
The thread 0x55bc has exited with code 0 (0x0).
wpf messagebox
My guess is that it fails silently as WPF does often. Did you check?
– Jan
Nov 9 at 18:15
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I ran into situation when some MessageBoxes with error messages were not displayed at all. After closer investigation, I was able to narrow down the problem to cases when a very long string is passed as messageBoxText
.
In such cases, call MessageBox.Show
does not display anything, returns MessageBoxResult.No
and, in most cases, there's a message in the Output
window saying The thread 0xHEXNUMBER has exited with code 0 (0x0)
. For me, this method silently fails.
This is very strange - WPF is a very mature technology and I expect this code to work according to spec or throw some exception (e.g. OutOfMemory, StackOverflowException). I've debugged the program and no manged or unmanged exceptions are thrown and caught.
What is the root cause of MessageBox not being displayed? Is there some easy way to debug such things (since no exceptions are thrown or logged). What is the messageBoxText length limit and what does it depend on (I could check that empirically on my computer, but would be conclusive for one OS/platform/.NET Framework version at best)?
Repro:
Here's a code which demonstrates the problem (it can be used with standard WPF Application template in Visual Studio).
MainWindow.xaml:
<Window x:Class="LongMessageInMessageBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Click="ShortMessage_Clicked">Short Message</Button>
<Button Grid.Row="1" Grid.Column="0" Click="LongMessage_Clicked">Long Message</Button>
</Grid>
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LongMessageInMessageBox
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
/// Method which shows that displaying short message works correctly
private void ShortMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("ShortMessage_Clicked");
var result = MessageBox.Show("Short Message");
Console.WriteLine(result);
/// Method which shows that displaying a long message does not work
private void LongMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("LongMessage_Clicked");
var longTextBuilder = new System.Text.StringBuilder(10000);
longTextBuilder.Append("Long Message n");
for (int i = 1; i <= 100000; i++)
longTextBuilder.Append(" ").Append(i);
var result = MessageBox.Show(longTextBuilder.ToString());
Console.WriteLine(result);
Sample from Output
window:
ShortMessage_Clicked
OK
ShortMessage_Clicked
OK
LongMessage_Clicked
No
The thread 0x55bc has exited with code 0 (0x0).
wpf messagebox
I ran into situation when some MessageBoxes with error messages were not displayed at all. After closer investigation, I was able to narrow down the problem to cases when a very long string is passed as messageBoxText
.
In such cases, call MessageBox.Show
does not display anything, returns MessageBoxResult.No
and, in most cases, there's a message in the Output
window saying The thread 0xHEXNUMBER has exited with code 0 (0x0)
. For me, this method silently fails.
This is very strange - WPF is a very mature technology and I expect this code to work according to spec or throw some exception (e.g. OutOfMemory, StackOverflowException). I've debugged the program and no manged or unmanged exceptions are thrown and caught.
What is the root cause of MessageBox not being displayed? Is there some easy way to debug such things (since no exceptions are thrown or logged). What is the messageBoxText length limit and what does it depend on (I could check that empirically on my computer, but would be conclusive for one OS/platform/.NET Framework version at best)?
Repro:
Here's a code which demonstrates the problem (it can be used with standard WPF Application template in Visual Studio).
MainWindow.xaml:
<Window x:Class="LongMessageInMessageBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Click="ShortMessage_Clicked">Short Message</Button>
<Button Grid.Row="1" Grid.Column="0" Click="LongMessage_Clicked">Long Message</Button>
</Grid>
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace LongMessageInMessageBox
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
/// Method which shows that displaying short message works correctly
private void ShortMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("ShortMessage_Clicked");
var result = MessageBox.Show("Short Message");
Console.WriteLine(result);
/// Method which shows that displaying a long message does not work
private void LongMessage_Clicked(object sender, RoutedEventArgs e)
Console.WriteLine("LongMessage_Clicked");
var longTextBuilder = new System.Text.StringBuilder(10000);
longTextBuilder.Append("Long Message n");
for (int i = 1; i <= 100000; i++)
longTextBuilder.Append(" ").Append(i);
var result = MessageBox.Show(longTextBuilder.ToString());
Console.WriteLine(result);
Sample from Output
window:
ShortMessage_Clicked
OK
ShortMessage_Clicked
OK
LongMessage_Clicked
No
The thread 0x55bc has exited with code 0 (0x0).
wpf messagebox
wpf messagebox
asked Nov 9 at 18:09
Tomasz Maczyński
743720
743720
My guess is that it fails silently as WPF does often. Did you check?
– Jan
Nov 9 at 18:15
add a comment |
My guess is that it fails silently as WPF does often. Did you check?
– Jan
Nov 9 at 18:15
My guess is that it fails silently as WPF does often. Did you check?
– Jan
Nov 9 at 18:15
My guess is that it fails silently as WPF does often. Did you check?
– Jan
Nov 9 at 18:15
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
MessageBox
class in WPF
(and WinForms) wraps the Win32 MessageBox
function, and doesn't throw an exception. In the old Win32 world error is reported by setting the last-error code, and if you don’t call GetLastError
to check, you can just keep going without knowing something is broken.
From Reference Source
//so it just translates the return code to a MessageBoxResult
MessageBoxResult result = Win32ToMessageBoxResult (UnsafeNativeMethods.MessageBox (new HandleRef (null, owner), messageBoxText, caption, style));
I have not tested the capacity of the lpText
string in the Win32 MessageBox function. But it is not surprising if the capacity limit is something like 1024
, 4096
or 65536
, after all, MessageBox
function is designed to display short message.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
MessageBox
class in WPF
(and WinForms) wraps the Win32 MessageBox
function, and doesn't throw an exception. In the old Win32 world error is reported by setting the last-error code, and if you don’t call GetLastError
to check, you can just keep going without knowing something is broken.
From Reference Source
//so it just translates the return code to a MessageBoxResult
MessageBoxResult result = Win32ToMessageBoxResult (UnsafeNativeMethods.MessageBox (new HandleRef (null, owner), messageBoxText, caption, style));
I have not tested the capacity of the lpText
string in the Win32 MessageBox function. But it is not surprising if the capacity limit is something like 1024
, 4096
or 65536
, after all, MessageBox
function is designed to display short message.
add a comment |
up vote
1
down vote
MessageBox
class in WPF
(and WinForms) wraps the Win32 MessageBox
function, and doesn't throw an exception. In the old Win32 world error is reported by setting the last-error code, and if you don’t call GetLastError
to check, you can just keep going without knowing something is broken.
From Reference Source
//so it just translates the return code to a MessageBoxResult
MessageBoxResult result = Win32ToMessageBoxResult (UnsafeNativeMethods.MessageBox (new HandleRef (null, owner), messageBoxText, caption, style));
I have not tested the capacity of the lpText
string in the Win32 MessageBox function. But it is not surprising if the capacity limit is something like 1024
, 4096
or 65536
, after all, MessageBox
function is designed to display short message.
add a comment |
up vote
1
down vote
up vote
1
down vote
MessageBox
class in WPF
(and WinForms) wraps the Win32 MessageBox
function, and doesn't throw an exception. In the old Win32 world error is reported by setting the last-error code, and if you don’t call GetLastError
to check, you can just keep going without knowing something is broken.
From Reference Source
//so it just translates the return code to a MessageBoxResult
MessageBoxResult result = Win32ToMessageBoxResult (UnsafeNativeMethods.MessageBox (new HandleRef (null, owner), messageBoxText, caption, style));
I have not tested the capacity of the lpText
string in the Win32 MessageBox function. But it is not surprising if the capacity limit is something like 1024
, 4096
or 65536
, after all, MessageBox
function is designed to display short message.
MessageBox
class in WPF
(and WinForms) wraps the Win32 MessageBox
function, and doesn't throw an exception. In the old Win32 world error is reported by setting the last-error code, and if you don’t call GetLastError
to check, you can just keep going without knowing something is broken.
From Reference Source
//so it just translates the return code to a MessageBoxResult
MessageBoxResult result = Win32ToMessageBoxResult (UnsafeNativeMethods.MessageBox (new HandleRef (null, owner), messageBoxText, caption, style));
I have not tested the capacity of the lpText
string in the Win32 MessageBox function. But it is not surprising if the capacity limit is something like 1024
, 4096
or 65536
, after all, MessageBox
function is designed to display short message.
edited 2 days ago
answered 2 days ago
kennyzx
9,44042262
9,44042262
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231198%2fwpf-messagebox-is-not-displayed-at-all-if-long-message-is-passed%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
My guess is that it fails silently as WPF does often. Did you check?
– Jan
Nov 9 at 18:15