CommunityToolkit / Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
https://aka.ms/windowsappsdk
Other
383 stars 89 forks source link

[WebView] Random System.NotSupportedException exceptions #259

Open DominikPalo opened 4 years ago

DominikPalo commented 4 years ago

A few of our clients randomly get this exception when using our WPF app:

Exception: System.NotSupportedException:
Unable to initialize the WebView control because the system is running a version of Windows that doesn't support this control. The WebView control runs only on Windows 10 April 2018 Update or later.

Restarting the app always helps, but the exception message is really confusing because:

  1. All of them are using the supported version of Windows, here is a winver screenshot from the client who encountered this issue yesterday (WebView requires 17110 build or a later, the client has 17134): image

  2. As I wrote, restarting the app on the same computer helps

  3. We perform a custom Windows version check during the app start: if Environment.OSVersion.Version.Build < 17110, the app is not even trying to load the WebView - it shows a descriptive error to the user and exits).

Here is the full stack trace:

23.4.2020 17:39:46 +02:00EThe floating window cannot be displayed.
Exception: System.NotSupportedException: Unable to initialize the WebView control because the system is running a version of Windows that doesn't support this control. The WebView control runs only on Windows 10 April 2018 Update or later.
  at Microsoft.Toolkit.Win32.UI.Controls.Interop.OSVersionHelper.ThrowIfBeforeWindows10April2018() in d:\a\1\s\WebView.Shared\Interop\OSVersionHelper.cs:line 112
  at Microsoft.Toolkit.Wpf.UI.Controls.WebView.Initialize() in d:\a\1\s\Microsoft.Toolkit.Wpf.UI.Controls.WebView\WebView.cs:line 755
  at Microsoft.Toolkit.Wpf.UI.Controls.WebViewHost.BuildWindowCore(HandleRef hwndParent) in d:\a\1\s\Microsoft.Toolkit.Wpf.UI.Controls.WebView\WebViewHost.cs:line 130
  at System.Windows.Interop.HwndHost.BuildWindow(HandleRef hwndParent)
  at System.Windows.Interop.HwndHost.BuildOrReparentWindow()
  at System.Windows.Interop.HwndHost.OnSourceChanged(Object sender, SourceChangedEventArgs e)
  at System.Windows.SourceChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
  at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
  at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
  at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
  at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
  at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
  at System.Windows.PresentationSource.UpdateSourceOfElement(DependencyObject doTarget, DependencyObject doAncestor, DependencyObject doOldParent)
  at System.Windows.PresentationSource.OnVisualAncestorChanged(DependencyObject uie, AncestorChangedEventArgs e)
  at System.Windows.UIElement.OnVisualAncestorChanged(Object sender, AncestorChangedEventArgs e)
  at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
  at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
  at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
  at System.Windows.Media.Visual.ProcessAncestorChangedNotificationRecursive(DependencyObject e, AncestorChangedEventArgs args)
  at System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
  at System.Windows.Media.Visual.AddVisualChild(Visual child)
  at System.Windows.FrameworkElement.set_TemplateChild(UIElement value)
  at System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(FrameworkElement container)
  at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
  at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
  at System.Windows.FrameworkElement.ApplyTemplate()
  at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
  at System.Windows.UIElement.Measure(Size availableSize)
  at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
  at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
  at System.Windows.UIElement.Measure(Size availableSize)
  at System.Windows.Controls.Border.MeasureOverride(Size constraint)
  at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
  at System.Windows.UIElement.Measure(Size availableSize)
  at System.Windows.Window.MeasureOverrideHelper(Size constraint)
  at System.Windows.Window.MeasureOverride(Size availableSize)
  at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
  at System.Windows.UIElement.Measure(Size availableSize)
  at System.Windows.Interop.HwndSource.SetLayoutSize()
  at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
  at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
  at System.Windows.Window.SetRootVisual()
  at System.Windows.Window.SetRootVisualAndUpdateSTC()
  at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
  at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
  at System.Windows.Window.CreateSourceWindowDuringShow()
  at System.Windows.Window.SafeCreateWindowDuringShow()
  at System.Windows.Window.ShowHelper(Object booleanBox)
  at System.Windows.Window.Show()
  at Slido.PowerPoint.SidebarManager.ShowBadge(Nullable`1 parentWindow)
michael-hawker commented 4 years ago

@DominikPalo this is the check:

https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/blob/f26fff3288090431b5746c39e214f44832c84cfd/WebView.Shared/Interop/OSVersionHelper.cs#L105-L113

I'm not sure why there are other conditions around workstation, but it's not just doing a version check, so some more details may be needed. The WebView will be replaced with WebView2, so that may be a better solution in the future.

FYI @pagoe-msft