OpenFileDialog hangs on Vista

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Tatham

    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.WriteLi ne ("OpenFileDialo g Test");
    try {
    OpenFileDialog ofd = new OpenFileDialog( );
    Console.WriteLi ne ("Ready to show dialog");
    if(ofd.ShowDial og() == DialogResult.OK ) {
    Console.WriteLi ne ("Filename is {0}", ofd.FileName);
    }
    }
    catch (Exception e) {
    Console.WriteLi ne ("Exception is {0}", e.ToString());
    }
    return 0 ;
    }
    }
  • Family Tree Mike

    #2
    Re: OpenFileDialog hangs on Vista

    The exception tells you how to fix the issue. You need simply to add
    [STAThread] before your main routine.

    "Nick Tatham" <ntatham1@nospa m.comwrote in message
    news:Xns9B3F607 A7EFC7ntxnd@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.WriteLi ne ("OpenFileDialo g Test");
    try {
    OpenFileDialog ofd = new OpenFileDialog( );
    Console.WriteLi ne ("Ready to show dialog");
    if(ofd.ShowDial og() == DialogResult.OK ) {
    Console.WriteLi ne ("Filename is {0}", ofd.FileName);
    }
    }
    catch (Exception e) {
    Console.WriteLi ne ("Exception is {0}", e.ToString());
    }
    return 0 ;
    }
    }

    Comment

    • Leon

      #3
      Re: OpenFileDialog hangs on Vista

      add this line,

      Application.Run (new Form());
      return (0);


      "Nick Tatham" <ntatham1@nospa m.comдÈëÏûÏ¢
      news:Xns9B3F607 A7EFC7ntxnd@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.WriteLi ne ("OpenFileDialo g Test");
      try {
      OpenFileDialog ofd = new OpenFileDialog( );
      Console.WriteLi ne ("Ready to show dialog");
      if(ofd.ShowDial og() == DialogResult.OK ) {
      Console.WriteLi ne ("Filename is {0}", ofd.FileName);
      }
      }
      catch (Exception e) {
      Console.WriteLi ne ("Exception is {0}", e.ToString());
      }
      return 0 ;
      }
      }

      Comment

      • Family Tree Mike

        #4
        Re: OpenFileDialog hangs on Vista

        The original post looked to be a console application to me.

        "Leon" <amoon.nj@163.c omwrote in message
        news:D5E2AE3B-AB93-4552-B809-62F1190DA377@mi crosoft.com...
        add this line,
        >
        Application.Run (new Form());
        return (0);
        >
        >
        "Nick Tatham" <ntatham1@nospa m.comдÈëÏûÏ¢
        news:Xns9B3F607 A7EFC7ntxnd@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.WriteLi ne ("OpenFileDialo g Test");
        >try {
        > OpenFileDialog ofd = new OpenFileDialog( );
        > Console.WriteLi ne ("Ready to show dialog");
        > if(ofd.ShowDial og() == DialogResult.OK ) {
        >Console.WriteL ine ("Filename is {0}", ofd.FileName);
        > }
        >}
        >catch (Exception e) {
        > Console.WriteLi ne ("Exception is {0}", e.ToString());
        >}
        >return 0 ;
        > }
        >}
        >

        Comment

        • Nick Tatham

          #5
          Re: OpenFileDialog hangs on Vista

          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


          Comment

          • Frans Bouma [C# MVP]

            #6
            Re: OpenFileDialog hangs on Vista

            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#)
            ------------------------------------------------------------------------

            Comment

            Working...