469,344 Members | 6,395 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

OpenFileDialog hangs on Vista


I have just purchased a new Dell Windows Vista Home Premium SP1 system.

One of my .NET 2.0 programs doesn't work on it. I have reduced it to the
tiny program below which fails in the same way.

On My old XP system, this code dsplays the OpenFileDialog, I select a
file and it logs the filename to the console.

On my Vista system, the OpenFileDialog never displays and the program
hangs on the ShowDialog method.

Does anyone have any ideas what is the cause? Is it a Vista config issue?

I can't reinstall the .NET 2.0 runtime as it says it is already
installed. I can't see anywhere in CP/Programs to uninstall it!

Shouldn't this just work out-of-the-box?

Thanks,

Nick

using System.Windows.Forms;
using System;

public class Test {

public static int Main(string [] args) {
Console.WriteLine ("OpenFileDialog Test");
try {
OpenFileDialog ofd = new OpenFileDialog();
Console.WriteLine ("Ready to show dialog");
if(ofd.ShowDialog() == DialogResult.OK) {
Console.WriteLine ("Filename is {0}", ofd.FileName);
}
}
catch (Exception e) {
Console.WriteLine ("Exception is {0}", e.ToString());
}
return 0 ;
}
}
Oct 22 '08 #1
5 3495
The exception tells you how to fix the issue. You need simply to add
[STAThread] before your main routine.

"Nick Tatham" <nt******@nospam.comwrote in message
news:Xn*******************@216.196.109.145...
>
I have just purchased a new Dell Windows Vista Home Premium SP1 system.

One of my .NET 2.0 programs doesn't work on it. I have reduced it to the
tiny program below which fails in the same way.

On My old XP system, this code dsplays the OpenFileDialog, I select a
file and it logs the filename to the console.

On my Vista system, the OpenFileDialog never displays and the program
hangs on the ShowDialog method.

Does anyone have any ideas what is the cause? Is it a Vista config issue?

I can't reinstall the .NET 2.0 runtime as it says it is already
installed. I can't see anywhere in CP/Programs to uninstall it!

Shouldn't this just work out-of-the-box?

Thanks,

Nick

using System.Windows.Forms;
using System;

public class Test {

public static int Main(string [] args) {
Console.WriteLine ("OpenFileDialog Test");
try {
OpenFileDialog ofd = new OpenFileDialog();
Console.WriteLine ("Ready to show dialog");
if(ofd.ShowDialog() == DialogResult.OK) {
Console.WriteLine ("Filename is {0}", ofd.FileName);
}
}
catch (Exception e) {
Console.WriteLine ("Exception is {0}", e.ToString());
}
return 0 ;
}
}
Oct 22 '08 #2
add this line,

Application.Run(new Form());
return (0);
"Nick Tatham" <nt******@nospam.com写入消息
news:Xn*******************@216.196.109.145...
>
I have just purchased a new Dell Windows Vista Home Premium SP1 system.

One of my .NET 2.0 programs doesn't work on it. I have reduced it to the
tiny program below which fails in the same way.

On My old XP system, this code dsplays the OpenFileDialog, I select a
file and it logs the filename to the console.

On my Vista system, the OpenFileDialog never displays and the program
hangs on the ShowDialog method.

Does anyone have any ideas what is the cause? Is it a Vista config issue?

I can't reinstall the .NET 2.0 runtime as it says it is already
installed. I can't see anywhere in CP/Programs to uninstall it!

Shouldn't this just work out-of-the-box?

Thanks,

Nick

using System.Windows.Forms;
using System;

public class Test {

public static int Main(string [] args) {
Console.WriteLine ("OpenFileDialog Test");
try {
OpenFileDialog ofd = new OpenFileDialog();
Console.WriteLine ("Ready to show dialog");
if(ofd.ShowDialog() == DialogResult.OK) {
Console.WriteLine ("Filename is {0}", ofd.FileName);
}
}
catch (Exception e) {
Console.WriteLine ("Exception is {0}", e.ToString());
}
return 0 ;
}
}
Oct 22 '08 #3
The original post looked to be a console application to me.

"Leon" <am******@163.comwrote in message
news:D5**********************************@microsof t.com...
add this line,

Application.Run(new Form());
return (0);
"Nick Tatham" <nt******@nospam.com写入消息
news:Xn*******************@216.196.109.145...
>>
I have just purchased a new Dell Windows Vista Home Premium SP1 system.

One of my .NET 2.0 programs doesn't work on it. I have reduced it to the
tiny program below which fails in the same way.

On My old XP system, this code dsplays the OpenFileDialog, I select a
file and it logs the filename to the console.

On my Vista system, the OpenFileDialog never displays and the program
hangs on the ShowDialog method.

Does anyone have any ideas what is the cause? Is it a Vista config issue?

I can't reinstall the .NET 2.0 runtime as it says it is already
installed. I can't see anywhere in CP/Programs to uninstall it!

Shouldn't this just work out-of-the-box?

Thanks,

Nick

using System.Windows.Forms;
using System;

public class Test {

public static int Main(string [] args) {
Console.WriteLine ("OpenFileDialog Test");
try {
OpenFileDialog ofd = new OpenFileDialog();
Console.WriteLine ("Ready to show dialog");
if(ofd.ShowDialog() == DialogResult.OK) {
Console.WriteLine ("Filename is {0}", ofd.FileName);
}
}
catch (Exception e) {
Console.WriteLine ("Exception is {0}", e.ToString());
}
return 0 ;
}
}
Oct 22 '08 #4
The exception tells you how to fix the issue. You need simply to add
[STAThread] before your main routine.
Thanks Mike.

I never got an exception - it just hung. So I couldn't follow the message!
But adding this construct fixed the problem - and my original problem as
well.

It doesn't explain why it worked fine on XP but not on Vista though.

Thanks for you help,

Nick
Oct 23 '08 #5
Nick Tatham wrote:
>The exception tells you how to fix the issue. You need simply to add
[STAThread] before your main routine.

Thanks Mike.

I never got an exception - it just hung. So I couldn't follow the message!
But adding this construct fixed the problem - and my original problem as
well.

It doesn't explain why it worked fine on XP but not on Vista though.
You do have some network shares on Vista? Does a normal explorer open
without problems?

If you disable all network shares and remove all DVDs/CD's from drives
does it work then? (Just for testing)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Oct 23 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rajendra KASHI | last post: by
3 posts views Thread by bobrad | last post: by
4 posts views Thread by Nagachandra Sekhar Grandhi | last post: by
8 posts views Thread by e-mid | last post: by
6 posts views Thread by barbara_dave | last post: by
13 posts views Thread by Randall Arnold | last post: by
5 posts views Thread by Eric Promislow | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.