Bugs

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?
 
J

Jochen Kalmbach

Ayende said:
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?

The main problem that you first have to define: What is the different
between release and debug build?

From the CLR-View the only difference is the
"System.Diagnostics.DebuggableAttribute"-Attribute.

This attribute has two properties:
- IsJITTrackingEnabled
- IsJITOptimizerDisabled

If both are "false", then you have a release build.

See:
http://msdn.microsoft.com/library/en-
us/cpref/html/frlrfsystemdiagnostics
debuggableattributeclasstopic.asp


An other difference might be the generation of PDB-Files. But the
current VS2002/2003 only support the generation of PDB-files with boths
attribut-members set to "true".

If you compile via command-line you can build a release version (no
DebuggableAttribute-Attribute or both set to false) AND have a PDB-file
generated.


--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
 
J

Jochen Kalmbach

Ayende said:
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?

Can you please provide a working example !?
Are you using "UseShellExecute" or normal start with "CreateProcess" !?

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
 
A

Ayende Rahien

Jochen Kalmbach said:
Can you please provide a working example !?
Are you using "UseShellExecute" or normal start with "CreateProcess" !?

This is the full source code that cause the problem:

public class Test
{
[System.MTAThread()]//NOTICE this, without this, everything works.
public static void Main(string []args)
{
System.Diagnostics.Process.Start("http://www.google.com");
}
}

Cause Win32Exception with "The requested section was not present in the
activation context"


I can't repreduce the problem of no *Thread attribute in a simple example
(complex stuff about threading and winforms.
 
W

Willy Denoyette [MVP]

The ThreadAttribute can't be the problem source.

Willy.


Ayende Rahien said:
Jochen Kalmbach said:
Can you please provide a working example !?
Are you using "UseShellExecute" or normal start with "CreateProcess" !?

This is the full source code that cause the problem:

public class Test
{
[System.MTAThread()]//NOTICE this, without this, everything works.
public static void Main(string []args)
{
System.Diagnostics.Process.Start("http://www.google.com");
}
}

Cause Win32Exception with "The requested section was not present in the
activation context"


I can't repreduce the problem of no *Thread attribute in a simple example
(complex stuff about threading and winforms.
 
A

Ayende Rahien

Willy Denoyette said:
The ThreadAttribute can't be the problem source.

Test it, then.
Using MTAThread - exception
Using STAThread - working
Not using at all - works (but I'd some problems with that)
 
W

Willy Denoyette [MVP]

Sorry my bad, that's why I'm allways using ProcessStartInfo to start an
external process, that way I wont be bitten by shell COM threading issues.

ProcessStartInfo sti = new ProcessStartInfo("IExplore.exe");
sti.Arguments = "www.google.com";
sti.UseShellExecute = true;
Process.Start(sti);

Willy.
 
A

Ayende Rahien

Willy Denoyette said:
Sorry my bad, that's why I'm allways using ProcessStartInfo to start an
external process, that way I wont be bitten by shell COM threading issues.

ProcessStartInfo sti = new ProcessStartInfo("IExplore.exe");
sti.Arguments = "www.google.com";
sti.UseShellExecute = true;
Process.Start(sti);

And that is nice, but what if the user's default browser is
Mozilla/Opera/Netscape/Non-IE?
 
S

Spire

read before responding

ProcessStartInfo sti = new ProcessStartInfo("IExplore.exe"); (use
path/opera.exe)
 
A

Ayende Rahien

I don't *know* what the user's default browser is!
Yes, I can find out, but that is too much trouble.

I can also do this:
Process.Start("cmd /c start " + url);

Which will also work (and give me the default browser), but I don't want to
use this (works on winnt only), I want to know what is wrong here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top