MauiHybridWebView icon indicating copy to clipboard operation
MauiHybridWebView copied to clipboard

Control Throws a Null Exception When Hosted on a ContentView

Open RuddySantos opened this issue 1 year ago • 4 comments
trafficstars

I am very new to this. The requirement I have calls for the webview to be hosted in a control (contentView). The HybridView shows fine and callling JS methods etc works. However, when I close the popup window that is hosting the control there is an object reference not set to an instance of an object exception on the OnHandlerChanged --> NavigationCore.

NOTE: This app uses Mopups for pushing/popping pages.

RuddySantos avatar Jan 23 '24 22:01 RuddySantos

Does it happen with regular MAUI BlazorWebView?

peterblazejewicz avatar Feb 03 '24 18:02 peterblazejewicz

We did not try it with the regular BlazorWebView. We are in the process of looking at other solutions but this HybridWebView is the best choice due to our constrains.

rsantos16 avatar Feb 06 '24 03:02 rsantos16

Hi @RuddySantos / @rsantos16 - I tried placing the HybridWebView inside a ContentView and that seemed to work just fine. Do you have a complete repro project that you can share for this?

Or perhaps a full stack trace of the exception?

I saw some places in the code that are possible culprits for a potential bug but it's hard to say without more info.

Eilon avatar Mar 12 '24 19:03 Eilon

Hi @Eilon , we face the same issue and this is the stack trace:

at ObjCRuntime.Runtime.ThrowException(IntPtr gchandle) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:line 2719
   at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 64
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in `/Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line` 96
   at MobileApp.Program.Main(String[] args) in /Users/johan/mobileapp/Platforms/iOS/Program.cs:line 13
2024-11-01 13:59:40.224525+0100 MobileApp[43460:4908687] Unhandled managed exception: Object reference not set to an instance of an object. (System.NullReferenceException)
   at HybridWebView.HybridWebView.get_PlatformWebView()
   at HybridWebView.HybridWebView.NavigateCore(String url)
   at HybridWebView.HybridWebView.Navigate(String url)
   at HybridWebView.HybridWebView.OnHandlerChanged()
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Foundation.NSAsyncSynchronizationContextDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:line 179

We use the Shell to navigate between pages and when coming back to a page with the HybridWebView component on it, it always crashes in our project.

johandep avatar Nov 01 '24 13:11 johandep