// WebView_ProcessFailed voidWebView_ProcessFailed(object sender, CoreWebView2ProcessFailedEventArgs e) { voidReinitIfSelectedByUser(string caption, string message) { this.Dispatcher.InvokeAsync(() => { var selection = MessageBox.Show(message, caption, MessageBoxButton.YesNo); if (selection == MessageBoxResult.Yes) { // The control cannot be re-initialized so we setup a new instance to replace it. // Note the previous instance of the control is disposed of and removed from the // visual tree before attaching the new one. if (_isControlInVisualTree) { RemoveControlFromVisualTree(webView); } webView.Dispose(); webView = GetReplacementControl(false); AttachControlToVisualTree(webView); // Set background transparent webView.DefaultBackgroundColor = System.Drawing.Color.Transparent; } }); } voidReloadIfSelectedByUser(string caption, string message) { this.Dispatcher.InvokeAsync(() => { var selection = MessageBox.Show(message, caption, MessageBoxButton.YesNo); if (selection == MessageBoxResult.Yes) { webView.Reload(); // Set background transparent webView.DefaultBackgroundColor = System.Drawing.Color.Transparent; } }); } boolIsAppContentUri(Uri source) { // Sample virtual host name for the app's content. // See CoreWebView2.SetVirtualHostNameToFolderMapping: https://learn.microsoft.com/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping return source.Host == "appassets.example"; } if (e.ProcessFailedKind == CoreWebView2ProcessFailedKind.FrameRenderProcessExited) { // A frame-only renderer has exited unexpectedly. Check if reload is needed. // In this sample we only reload if the app's content has been impacted. foreach (CoreWebView2FrameInfo frameInfo in e.FrameInfosForFailedProcess) { if (IsAppContentUri(new System.Uri(frameInfo.Source))) { System.Threading.SynchronizationContext.Current.Post((_) => { ReloadIfSelectedByUser("App content frame unresponsive", "Browser render process for app frame exited unexpectedly. Reload page?"); }, null); } } return; } // Show the process failure details. Apps can collect info for their logging purposes. this.Dispatcher.InvokeAsync(() => { StringBuilder messageBuilder = new StringBuilder(); messageBuilder.AppendLine($"Process kind: {e.ProcessFailedKind}"); messageBuilder.AppendLine($"Reason: {e.Reason}"); messageBuilder.AppendLine($"Exit code: {e.ExitCode}"); messageBuilder.AppendLine($"Process description: {e.ProcessDescription}"); MessageBox.Show(messageBuilder.ToString(), "Child process failed", MessageBoxButton.OK); }); if (e.ProcessFailedKind == CoreWebView2ProcessFailedKind.BrowserProcessExited) { ReinitIfSelectedByUser("Browser process exited", "Browser process exited unexpectedly. Recreate webview?"); } elseif (e.ProcessFailedKind == CoreWebView2ProcessFailedKind.RenderProcessUnresponsive) { ReinitIfSelectedByUser("Web page unresponsive", "Browser render process has stopped responding. Recreate webview?"); } elseif (e.ProcessFailedKind == CoreWebView2ProcessFailedKind.RenderProcessExited) { ReloadIfSelectedByUser("Web page unresponsive", "Browser render process exited unexpectedly. Reload page?"); } }
在 windows 搜索栏中搜索
eventvwr(又叫事件查看器),打开后找到
【应用程序和服务日志】/【Microsoft】/【Windows】/【CodeIntegrity】/【Operational】,找到错误项进行查看。
1 2 3
# 例如出现如下错误,说明是 Ldxghijt64.dll 注入失败导致的
Code Integrity determined that a process (\Device\HarddiskVolume5\Program Files (x86)\Microsoft\EdgeWebView\Application\114.0.1823.67\msedgewebview2.exe) attempted to load \Device\HarddiskVolume5\Windows\System32\Ldxghijt64.dll that did not meet the Microsoft signing level requirements.