Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UWP应用程序在尝试从WebView ScriptNotify打开文件选取器时崩溃,即使在由Dispatcher运行时也是如此_C#_.net_Webview_Uwp_Filepicker - Fatal编程技术网

C# UWP应用程序在尝试从WebView ScriptNotify打开文件选取器时崩溃,即使在由Dispatcher运行时也是如此

C# UWP应用程序在尝试从WebView ScriptNotify打开文件选取器时崩溃,即使在由Dispatcher运行时也是如此,c#,.net,webview,uwp,filepicker,C#,.net,Webview,Uwp,Filepicker,我的应用程序有一个WebView for UI,它通过使用window.external.notify通知后端代码: public MainPage() { this.InitializeComponent(); this.web.ScriptNotify += this.Web_ScriptNotify; this.web.Navigate(new Uri("ms-appx-we

我的应用程序有一个WebView for UI,它通过使用
window.external.notify通知后端代码:

        public MainPage()
        {
            this.InitializeComponent();

            this.web.ScriptNotify += this.Web_ScriptNotify;
            this.web.Navigate(new Uri("ms-appx-web:///index.html"));
        }

        private void Web_ScriptNotify(object sender, NotifyEventArgs e)
        {
            _ = this.Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal, 
                async () =>
            {
                var d = new FileOpenPicker();

                // Changing UI text is okay
                this.lbl.Text = "Hello!";

                // Crash here:
                var file = await d.PickSingleFileAsync();
            });
        }
我要执行的命令之一是打开一个文件选择器。但是,它会因以下异常而崩溃:
System.Runtime.InteropServices.COMException:“未指定的错误”
。我认为这是因为我试图从UI线程外部打开它,所以我已经在调度程序中运行了它,但它仍然发生


我该怎么办?

它崩溃是因为我没有设置FileTypeFilter,而不是因为该事件。添加此选项有助于:

diagOpen.FileTypeFilter.Add("*");

抱歉,找到问题了。它崩溃是因为我没有设置
FileTypeFilter
,而不是因为该事件。