launching IE from winforms app ...error

M

Mike Hennessy

I have a strange error occuring in my winforms app that I can't seem to find
any fix for.

With a button click I am launching something like the following:

string url ="http://www.microsoft.com"
System.Diagnostics.Process.Start(url);

Now, it USED to work in my current winforms app. However, now it throws an
error everytime when I try to launch this.

It throws: "An unhandled exception of type
'System.ComponentModel.Win32Exception' occurred in system.dll

Additional information: The system cannot find the file specified"

Now, if i start a clean winforms app, and put the same code behind a button
click, it works!!

So what's the deal? It seems somehow this project has been compromised, but
nothing else is throwing errors or giving me any hints.

Your help is appreciated!
 
H

Herfried K. Wagner [MVP]

* "Mike Hennessy said:
I have a strange error occuring in my winforms app that I can't seem to find
any fix for.

With a button click I am launching something like the following:

string url ="http://www.microsoft.com"
System.Diagnostics.Process.Start(url);

Now, it USED to work in my current winforms app. However, now it throws an
error everytime when I try to launch this.

It throws: "An unhandled exception of type
'System.ComponentModel.Win32Exception' occurred in system.dll

Additional information: The system cannot find the file specified"

Now, if i start a clean winforms app, and put the same code behind a button
click, it works!!

Does that work?

\\\
Dim psi As New ProcessStartInfo()
psi.UseShellExecute = True
psi.FileName = "http://www.microsoft.com"
Process.Start(psi)
///
 
Y

Ying-Shen Yu[MSFT]

Hi Mike,

Thanks for posting in the community!

From your description, my understanding to your problem now is
the Process.Start(url) doesn't work in your program, it throws Win32 app
and says the specified file could not be found. However, it works fine in a
newly created simple winform app. Am I right? If I misundersood your
problem please let me know.

I'd like to know if you had checked the ApartmentState, because
Process.Start method internal invokes the API ShellExecuteEx internally
which requires to do some DDE to launch the browser, According to the Doc
of Process.Start it needs the thread model is STA.
You may check your thread model by adding a line like:
Debug.WriteLine(System.Threading.Thread.ApartmentState);

If it is not STA, you may set the STAThread attribute on your Main function
and try again to see if the problem still persists.

If the problem still persists, we need do some further investigation on
this issue, please help me collection some information about this issue.
1. I'd like first to make sure if you are able to lauch the browser
successfully in "Run Dialog" (the dialog pops up by pressing Windows+R key).

2. In your description, the method returns the File not found, Maybe we can
use filemon to monitor your program to see if there is any exe file open
but return as "File not found", note there might be some other files (such
as ".config" "*.local") couldn't be found, it's ok and should not related
to this problem. please paste a log to

To help this issue further, I need a repro sample to do further
investigation, since you couldn't repro this problem in a simple project,
is it possible to simplify your project to seperate the program part?

If you have any updates on this issue, please feel free to reply this
thread.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 
M

Mike Hennessy

Hi Ying-Shen, thanks for the reply,

After Looking into this further, I found out the culprit of the problem,
although I'm not sure why it's causing a problem.

I'm using a new GridControl from a company called Xceed. It's basically a
suped-up Winforms Grid that lets you to a ton of stuff the normal winforms
grid control doesn't do.

Anyway, I had a reference to their Xceed.Grid for .NET Designer in my
project. This reference seems to be causing the problem mentioned below.

On my fresh new winforms app with one button, I just added this reference( I
don't even use it in the project!) and sure enough I got the error. I remove
the reference and everything is fine.

I'll send a bug report to the company, but it just seems awefully strange.

Thanks,
Mike



"Ying-Shen Yu[MSFT]" said:
Hi Mike,

Thanks for posting in the community!

From your description, my understanding to your problem now is
the Process.Start(url) doesn't work in your program, it throws Win32 app
and says the specified file could not be found. However, it works fine in a
newly created simple winform app. Am I right? If I misundersood your
problem please let me know.

I'd like to know if you had checked the ApartmentState, because
Process.Start method internal invokes the API ShellExecuteEx internally
which requires to do some DDE to launch the browser, According to the Doc
of Process.Start it needs the thread model is STA.
You may check your thread model by adding a line like:
Debug.WriteLine(System.Threading.Thread.ApartmentState);

If it is not STA, you may set the STAThread attribute on your Main function
and try again to see if the problem still persists.

If the problem still persists, we need do some further investigation on
this issue, please help me collection some information about this issue.
1. I'd like first to make sure if you are able to lauch the browser
successfully in "Run Dialog" (the dialog pops up by pressing Windows+R key).

2. In your description, the method returns the File not found, Maybe we can
use filemon to monitor your program to see if there is any exe file open
but return as "File not found", note there might be some other files (such
as ".config" "*.local") couldn't be found, it's ok and should not related
to this problem. please paste a log to

To help this issue further, I need a repro sample to do further
investigation, since you couldn't repro this problem in a simple project,
is it possible to simplify your project to seperate the program part?

If you have any updates on this issue, please feel free to reply this
thread.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 
Y

Ying-Shen Yu[MSFT]

Hi Mike,

Thanks for your reply!

I'm glad to see you have found the cause. If you need further help or meet
any other questions on winform related issues, please feel free to post it
in our community!



Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 

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