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(u rl); 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(u rl) 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 SetExceptionHan dlers()
{
System.AppDomai n.CurrentDomain .UnhandledExcep tion+=new
UnhandledExcept ionEventHandler (CurrentDomain_ UnhandledExcept ion);
System.Windows. Forms.Applicati on.ThreadExcept ion+=new
System.Threadin g.ThreadExcepti onEventHandler
(Application_Th readException);
}
public static void HandleException (Exception ex)
{
if(ex==null)
return;
using(DetailedE rrorInfo dei = new DetailedErrorIn fo(ex))
{
dei.ShowDialog( );
}
}
private static void CurrentDomain_U nhandledExcepti on(object sender,
UnhandledExcept ionEventArgs e)
{
HandleException (e.ExceptionObj ect as Exception);
}
private static void Application_Thr eadException(ob ject sender,
System.Threadin g.ThreadExcepti onEventArgs e)
{
HandleException (e.Exception);
}
[ STAThread()]
public static void Main(string [] args)
{
SetExceptionHan dlers();
Test();
Console.WriteLi ne("Test passeed");
private void Test()
{
throw new InvalidOperatio nException("Tes t");
}
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(u rl); 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(u rl) 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 SetExceptionHan dlers()
{
System.AppDomai n.CurrentDomain .UnhandledExcep tion+=new
UnhandledExcept ionEventHandler (CurrentDomain_ UnhandledExcept ion);
System.Windows. Forms.Applicati on.ThreadExcept ion+=new
System.Threadin g.ThreadExcepti onEventHandler
(Application_Th readException);
}
public static void HandleException (Exception ex)
{
if(ex==null)
return;
using(DetailedE rrorInfo dei = new DetailedErrorIn fo(ex))
{
dei.ShowDialog( );
}
}
private static void CurrentDomain_U nhandledExcepti on(object sender,
UnhandledExcept ionEventArgs e)
{
HandleException (e.ExceptionObj ect as Exception);
}
private static void Application_Thr eadException(ob ject sender,
System.Threadin g.ThreadExcepti onEventArgs e)
{
HandleException (e.Exception);
}
[ STAThread()]
public static void Main(string [] args)
{
SetExceptionHan dlers();
Test();
Console.WriteLi ne("Test passeed");
private void Test()
{
throw new InvalidOperatio nException("Tes t");
}
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?
Comment