Xamarin.Forms : UWP platform : Unable to cast object of type 'Windows.UI.Xaml.Controls.WebView' to type 'Windows.UI.Xaml.Controls.IWebView6'

Viewed 89
  • Xamarin.Forms version: 5.0.0.2401

  • Windows version:

    • OS Name: Microsoft Windows 10 Enterprise
    • OS Version: 10.0.16299 Build 16299
  • Platform: UWP (Windows Universal Platform):

  • Reproducibility: 100%

  • Problem occurs each time using WebView with the following stacktrace:

      StackTrace:
     at System.StubHelpers.StubHelpers.GetCOMIPFromRCW_WinRT(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget)
     at Windows.UI.Xaml.Controls.WebView.add_SeparateProcessLost(TypedEventHandler`2 handler)
     at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.AddEventHandler[T](Func`2 addMethod, Action`1 removeMethod, T handler)
     at System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal.AddEventHandler[T](Func`2 addMethod, Action`1 removeMethod, T handler)
     at Xamarin.Forms.Platform.UWP.WebViewRenderer.Connect(WebView webView)
     at Xamarin.Forms.Platform.UWP.WebViewRenderer.OnElementChanged(ElementChangedEventArgs`1 e)
     at MyApp.UWP.Renderers.XWebViewRenderer.OnElementChanged(ElementChangedEventArgs`1 e) in MyApp.UWP\Renderers\XWebViewRenderer.cs:line 30
     at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
     at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.SetupVisualElement(VisualElement view)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load()
     at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
     at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.SetupVisualElement(VisualElement view)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load()
     at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
     at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.SetupVisualElement(VisualElement view)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load()
     at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element)
     at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.SetupVisualElement(VisualElement view)
     at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e)
     at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
     at Xamarin.Forms.Element.OnChildAdded(Element child)
     at Xamarin.Forms.VisualElement.OnChildAdded(Element child)
     at Xamarin.Forms.Layout`1.OnChildAdded(Element child)
     at Xamarin.Forms.AbsoluteLayout.OnChildAdded(Element child)
     at Xamarin.Forms.Layout.OnInternalAdded(View view)
     at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
     at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
     at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
     at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
     at System.Collections.ObjectModel.Collection`1.Add(T item)
     at Xamarin.Forms.ObservableWrapper`2.Add(TRestrict item)
    

Do you have any idea about the root cause and solution to fix this issue?

Many thanks

1 Answers

Xamarin.Forms : UWP platform : Unable to cast object of type 'Windows.UI.Xaml.Controls.WebView' to type 'Windows.UI.Xaml.Controls.IWebView6'

The problem should be related with the OS Version 16299, please check IWebView6 interface, and it only contains one SeparateProcessLost event. but the SeparateProcess webview model avaiable start from Windows 10, version 1803 (introduced in 10.0.17134.0). So the workaround is update your OS to latest verison or reduce the xamarin form package version.

Related