views:

322

answers:

1

I have been searching up and down the web and unfortunately never came across an issue quite like mine, so here goes:

My C# WPF application won't show me no OpenFileDialogs or SafeFileDialogs.

private void btnBrowseNet_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.CheckPathExists = true;
        ofd.Multiselect = false;
        ofd.Title = "Open Network Configuration Batch file...";
        ofd.ValidateNames = true;
        ofd.Filter = "Comma Seperated Value Files|*.csv";

        if (ofd.ShowDialog() == true)
        {
           //...
        }
    }

This exact code does in one occasion exactly what it is supposed to do and hardly five minutes later I can click the button all I want, nothing happens but the mouse pointer turning into a little busy-indicator and then nothing. I can step through the method or do something like this

bool? shown = ofd.ShowDialog();

But no matter what, the dialog won't show. Of course, shown will be false in that case. I wasted one and a half hours searching yesterday and right when I quit I tried it again and all of a sudden it worked. Sometimes it works, sometimes it doesn't. But it seems to be project specific because I can paste the same code into a new project and it works like it is supposed to do. Also, that's the only thing about the project that seems fishy. Everything else works as intended.

Has anyone on here ever experienced something similar and thus an idea of what on earth I could do? Any help weould be highly appreciated.

+1  A: 

There are a large number of possible failure modes for OpenFileDialog. Using one exposes your app to just about any shell extension that's installed on your machine. Many of which can be very destabilizing, it isn't that likely that the extension author has checked if it works properly in a WPF process.

Tackle this problem by running SysInternals' AutoRuns utility. Click the Explorer tab and look for the groups that have "ShellEx" in their name. Uncheck anything that wasn't published by Microsoft. Reboot and check if the problem is solved.

Hans Passant
Thanks for the advice! Sadly though, as you pointed out, there is a large number of possible failure modes and disabling all third party shell extension was not the one I encountered. Even after turning everything off and rebooting the problem persists.Also, let me point out that the dialogs work in another project at the same time - flawlessly.I would like to vote you answer up, though, as it seems pretty useful to me. Unfortunately I can't do that until I gathered some more rep :P
Koarl