简体   繁体   中英

Microsoft.Win32.OpenFileDialog dosn't show while debugging?

I'm building a application on Visual Studio 2015 in C#. I'm using Microsoft.Win32.OpenFileDialog to get a file from machine, but while debugging the code stands still at "dlg.showDialog();" and the dialog box dosn't shown up.

public static void OpenDialog()
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Title = "ABC";
            dlg.ShowDialog();
        }

Please suggest if there is any other way?

Microsoft.Win32.OpenFileDialog dosn't show while debugging?

I have tested your code in my side and I did not face the error as you described and I can open the dialog successfully. So please try these suggestions:

1) make sure that your project is a desktop project rather than a console project.

2) reference PresentationFramework.dll under Add Reference-->Reference-->Assemblies-->select PresentationFramework .

3) disable any third party extensions under Tools --> Extensions and Updates to check whether an extension caused this behavior.

4) then close VS Instance, delete .vs hidden folder under solution folder, bin , obj folder, then restart your project and then test again.

Then you can set breakpoint to test whether it runs successfully.

5) try to create a new project to test these code and if it still does not work, please repair your VS(run the vs2015 installer program and click Repair ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM