473,322 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Bugs

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_Unhan dledException);
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?
Nov 16 '05 #1
10 1725
Ayende Rahien wrote:
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/
Nov 16 '05 #2
Ayende Rahien wrote:
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/
Nov 16 '05 #3

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn**********************************@207.46.2 48.16...
Ayende Rahien wrote:
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" !?


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.
Nov 16 '05 #4
The ThreadAttribute can't be the problem source.

Willy.
"Ayende Rahien" <Ay****@no.spam> wrote in message
news:er**************@tk2msftngp13.phx.gbl...

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn**********************************@207.46.2 48.16...
Ayende Rahien wrote:
> 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" !?


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.

Nov 16 '05 #5

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:e4**************@TK2MSFTNGP10.phx.gbl...
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)
Nov 16 '05 #6
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.

"Ayende Rahien" <Ay****@no.spam> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:e4**************@TK2MSFTNGP10.phx.gbl...
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)

Nov 16 '05 #7

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl...
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?
Nov 16 '05 #8
read before responding

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

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

Nov 16 '05 #9
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.
"Spire" <sp**********@mail.com> wrote in message
news:c4**********@ls219.htnet.hr...
read before responding

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

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


Nov 16 '05 #10
What is wrong here is simply that doing it 'your way - using Shell API's
under the covers', the calling thread must be running in an STA.

For more info read this (especially the remarks):
http://msdn.microsoft.com/library/de...tarttopic2.asp

Willy.

"Ayende Rahien" <Ay****@no.spam> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
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.
"Spire" <sp**********@mail.com> wrote in message
news:c4**********@ls219.htnet.hr...
read before responding

ProcessStartInfo sti = new ProcessStartInfo("IExplore.exe"); (use
path/opera.exe)
>
> And that is nice, but what if the user's default browser is
> Mozilla/Opera/Netscape/Non-IE?
>
>



Nov 16 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mudge | last post by:
Hi, I'm trying to help my hosting company decide whether or not to upgrade to php 5. My hosting company does not want to upgrade to php 5 if it has bugs that would cause problems. So i'm doing...
83
by: kartik | last post by:
there seems to be a serious problem with allowing numbers to grow in a nearly unbounded manner, as int/long unification does: it hides bugs. most of the time, i expect my numbers to be small. 2**31...
3
by: Brett C. | last post by:
Anthony Baxter, our ever-diligent release manager, mentioned this past week that Python 2.3.5 will most likely come to fruition some time in January (this is not guaranteed date). This means that...
4
by: Alex Bell | last post by:
There have been several postings recently dealing with bugs in Internet Explorer. Can anyone point me to a review of these bugs and how to work around them? Regards, Alex
20
by: Prashanth Badabagni | last post by:
hi, i'm prashanth Badabagni .. Can anyone tell me the BUGS present in C language whether programming or syntactical BUGS .... Thanks in advance ... Prashanth Badabagni
9
by: David Teran | last post by:
Hi, we are currently using another database product but besides some licensing issues we are finding more and more problems with the database. We are evaluating PostgreSQL and it looks quite...
2
by: TheSteph | last post by:
Using : Windows 2000 Pro SP4 / VS.NET 2005 / .NET 2.0 / C# - All updates done. I have several bugs when I use the DataGridView : When scrolling (or after scrolling) the grid have these...
19
by: Alan Silver | last post by:
Hello, Having discovered what I believe to be two CSS bugs in IE7, I have submitted bug reports to MS. AFAIK, these don't get acted on until they receive votes form others to say they are worth...
15
by: Gary Peek | last post by:
Can anyone tell us the browsers/versions that exhibit errors when tables are nested too deeply? And how many levels of nesting produces errors? (not a tables vs CSS question)
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.