C# UWP应用程序在尝试从WebView ScriptNotify打开文件选取器时崩溃,即使在由Dispatcher运行时也是如此
我的应用程序有一个WebView for UI,它通过使用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
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
,而不是因为该事件。