I'm trying to use CommonOpenFileDialog's folder picker, as described in this answer. The problem is that even with a very stripped down example project I get an exception when trying to use CommonOpenFileDialog's ShowDialog() function.
using Microsoft.WindowsAPICodePack.Dialogs; namespace DialogTest < class Program < public static void Main(string[] args) < CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.InitialDirectory = "C:\\Users"; dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog(); if (result == CommonFileDialogResult.Ok) < //Do Stuff >> > >
This code produces the following exception at dialog.ShowDialog(); :
System.Runtime.InteropServices.COMException was unhandled ErrorCode=-2147023116 HResult=-2147023116 Message=A null reference pointer was passed to the stub. (Exception from HRESULT: 0x800706F4) Source=Microsoft.WindowsAPICodePack.Shell StackTrace: at Microsoft.WindowsAPICodePack.Dialogs.IFileDialog.SetFileName(String pszName) at Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialog.ApplyNativeSettings(IFileDialog dialog) in c:\projects\Windows API Code Pack 1.1\source\WindowsAPICodePack-NuGet\Shell\CommonFileDialogs\CommonFileDialog.cs:line 768 at Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialog.ShowDialog() in c:\projects\Windows API Code Pack 1.1\source\WindowsAPICodePack-NuGet\Shell\CommonFileDialogs\CommonFileDialog.cs:line 609 at DialogTest.Program.Main(String[] args) in c:\users\obscerno\documents\visual studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 13 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: