Skip to content

Commit

Permalink
Fix NullRef on Android due to missing field on .NET 8
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
Eilon committed Sep 18, 2023
1 parent d21a70d commit 78f708e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion HybridWebView/HybridWebViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public static void MapHybridWebViewClient(IWebViewHandler handler, IWebView webV
// in such a way that it knows of the custom MauiWebViewClient that we're creating. So, we use private reflection to set it on the
// instance. We might end up duplicating WebView/BlazorWebView anyway, in which case we wouldn't need this workaround.
var webViewClientField = typeof(WebViewHandler).GetField("_webViewClient", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.FlattenHierarchy);
webViewClientField!.SetValue(handler, webViewClient);

// Starting in .NET 8.0 the private field is gone and this call isn't necessary, so we only set if it needed
webViewClientField?.SetValue(handler, webViewClient);
}
}
#endif
Expand Down

0 comments on commit 78f708e

Please sign in to comment.