A
Ayende Rahien
Recently I've encountered two highly annoying bugs in the framework,
anyone who knows how to solve them would be most appriciated.
1) I'm trying to do Process.Start(url); and get a Win32Exception, after
quite a bit of testing I found out that the reason for this is that I
didn't have STAThread attribute. Process.Start(url) throws when I don't
have an attribute at all, or when I have MTAThrea, anyone can tell me
why?
I looked around, and it seemed that many other people have encountered
this problem. I've the workaround, but I want to know what is going on
here!
2) The following code throw an exception and abort the program, it
shouldn't!
public static void SetExceptionHandlers()
{
System.AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
System.Windows.Forms.Application.ThreadException+=new
System.Threading.ThreadExceptionEventHandler
(Application_ThreadException);
}
public static void HandleException(Exception ex)
{
if(ex==null)
return;
using(DetailedErrorInfo dei = new DetailedErrorInfo(ex))
{
dei.ShowDialog();
}
}
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
HandleException(e.ExceptionObject as Exception);
}
private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)
{
HandleException(e.Exception);
}
[ STAThread()]
public static void Main(string [] args)
{
SetExceptionHandlers();
Test();
Console.WriteLine("Test passeed");
private void Test()
{
throw new InvalidOperationException("Test");
}
There is nothing wrong here as far as I can tell, but it still will give
me the silly default dialog. The whole point is to have a better dialog
there!
3) Not related to bugs, but does anyone knows whatever there is a way to
know at *runtime* whatever this is a debug or release build?
anyone who knows how to solve them would be most appriciated.
1) I'm trying to do Process.Start(url); and get a Win32Exception, after
quite a bit of testing I found out that the reason for this is that I
didn't have STAThread attribute. Process.Start(url) throws when I don't
have an attribute at all, or when I have MTAThrea, anyone can tell me
why?
I looked around, and it seemed that many other people have encountered
this problem. I've the workaround, but I want to know what is going on
here!
2) The following code throw an exception and abort the program, it
shouldn't!
public static void SetExceptionHandlers()
{
System.AppDomain.CurrentDomain.UnhandledException+=new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
System.Windows.Forms.Application.ThreadException+=new
System.Threading.ThreadExceptionEventHandler
(Application_ThreadException);
}
public static void HandleException(Exception ex)
{
if(ex==null)
return;
using(DetailedErrorInfo dei = new DetailedErrorInfo(ex))
{
dei.ShowDialog();
}
}
private static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
HandleException(e.ExceptionObject as Exception);
}
private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)
{
HandleException(e.Exception);
}
[ STAThread()]
public static void Main(string [] args)
{
SetExceptionHandlers();
Test();
Console.WriteLine("Test passeed");
private void Test()
{
throw new InvalidOperationException("Test");
}
There is nothing wrong here as far as I can tell, but it still will give
me the silly default dialog. The whole point is to have a better dialog
there!
3) Not related to bugs, but does anyone knows whatever there is a way to
know at *runtime* whatever this is a debug or release build?