Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with MessageBox.Show in catch
    primarykey
    data
    text
    <p>When I try to run the following code It causes an Unhandled Exception. After much tweeking with the code I found if commented out the MessageBox.Show line the problem goes away! Unusually I have used MessageBox.Show statments in other catch{ } segments in other parts of the code with no problems. My question is does anyone know why its causing the exception?</p> <p>(P.s Reports_Group_Chooser is a ComboBox)</p> <p>The Code:</p> <pre><code>string GroupName= (string)Reports_Group_Chooser.SelectedItem; byte[] ConfigBytes= new byte[]{}; try{ ConfigBytes= File.ReadAllBytes("Reports/"+ GroupName.ToLower() +".grp"); }catch{ MessageBox.Show("The file for this group is missing. Cannot continue.","File Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Reports_Group_Chooser.Items.RemoveAt(NewGroup); Reports_Group_Chooser.SelectedIndex= 0; } </code></pre> <p>The error (well most of it):</p> <blockquote> <p>Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at System.Windows.Forms.ComboBox.DropDownListBoxFinished () [0x00000] at (wrapper remoting-invoke-with-check) System.Windows.Forms.ComboBox:DropDownListBoxFinished () at System.Windows.Forms.ComboBox+ComboListBox.HideWindow () [0x00000] at System.Windows.Forms.ComboBox+ComboListBox.OnMouseUp (System.Windows.Forms.MouseEventArgs e) [0x00000] at System.Windows.Forms.Control.WmLButtonUp (System.Windows.Forms.Message&amp; m) [0x00000] at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&amp; m) [0x00000] at System.Windows.Forms.ComboBox+ComboListBox.WndProc (System.Windows.Forms.Message&amp; m) [0x00000] at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message&amp; m) [0x00000] at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message&amp; m) [0x00000] at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000] at System.Windows.Forms.XplatUIX11.DispatchMessage (System.Windows.Forms.MSG&amp; msg) [0x00000] at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG&amp; msg) [0x00000] at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000]</p> </blockquote> <p>Any help appreciated Michael</p> <p>UPDATE This is an example of a working MessageBox.Show in my code which does not cause an error:</p> <pre><code>GlobalConfig= new Dictionary&lt;string, string&gt;(); byte[] ConfigBytes= new byte[]{}; try{ ConfigBytes= System.IO.File.ReadAllBytes("Config.cfg"); }catch{ MessageBox.Show("Global ettings file does not exist. Cannot continue.","File Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); GlobalConfig.Add("StoreNumber",""); GlobalConfig.Add("Error","Y"); } </code></pre> <p>Update update:</p> <p>It seems the problem is just having the MessageBox.Show within a combobox event: The following code still presents the same error:</p> <pre><code>private void Reports_GroupChanged(object sender,EventArgs e){ MessageBox.Show("The file for this group is missing. Cannot continue.","File Error",MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload