A
Andrus
T reproduce, run code.
Observed: Vista dialog Myapp stops working
Expected: Messagebox.
If RaiseTypeLoadException() is removed from Main(), Messagebox occurs.
ThreadException event does not occur before MainForm is instantiated.
How to fix ?
Andrus.
using System;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
class Test
{
static void Main()
{
Application.ThreadException += Application_ThreadException;
RaiseTypeLoadException();
Application.Run(new MainForm());
}
class MainForm : Form
{
protected override void OnLoad(EventArgs e)
{
RaiseTypeLoadException();
base.OnLoad(e);
}
}
public static void RaiseTypeLoadException()
{
Assembly asm = Assembly.GetEntryAssembly();
asm.GetType("Bad", true);
}
static void Application_ThreadException(object sender,
ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.ToString());
}
}
Observed: Vista dialog Myapp stops working
Expected: Messagebox.
If RaiseTypeLoadException() is removed from Main(), Messagebox occurs.
ThreadException event does not occur before MainForm is instantiated.
How to fix ?
Andrus.
using System;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
class Test
{
static void Main()
{
Application.ThreadException += Application_ThreadException;
RaiseTypeLoadException();
Application.Run(new MainForm());
}
class MainForm : Form
{
protected override void OnLoad(EventArgs e)
{
RaiseTypeLoadException();
base.OnLoad(e);
}
}
public static void RaiseTypeLoadException()
{
Assembly asm = Assembly.GetEntryAssembly();
asm.GetType("Bad", true);
}
static void Application_ThreadException(object sender,
ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.ToString());
}
}