.NET MAUI - Unhandled Exception located in 'Microsoft.Maui.Platform.MauiWebView'

UnexpectedGrit 11 Reputation points
2024-05-31T21:58:54.9366667+00:00

XAML WebView element definitions:

<WebView
	x:Name="ElectricArcGif"
    VerticalOptions="Center"
    HeightRequest="40" />

<WebView
    x:Name="ClintHatGif"
    VerticalOptions="Center"
    HeightRequest="200" />

C# code-behind:

public partial class NavOpenTechStartPage : ContentPage
{
    public NavOpenTechStartPage()
	{
        InitializeComponent();
        ElectricArcGif.Source = new UrlWebViewSource
        {
            Url = "file:///android_asset/electricityarc.html"
        };
        ClintHatGif.Source = new UrlWebViewSource
        {
            Url = "file:///android_asset/clinthat.html"
        };
    }
    private async void BackButton_Clicked(object sender, EventArgs e)
    {
        await Shell.Current.GoToAsync("//MainPage");
    }
    private async void RapidFirePDF_Clicked(object sender, EventArgs e)
    {
        await Shell.Current.GoToAsync("NavRapidFirePDF");
    }
}

HTML files

<html>
<body style="background-color: lightyellow; padding: 0; margin: 0; display: flex; justify-content: center; align-items: center; height: 100vh">
    <img src="electricityarc.gif" style="height: 40px; width: 100%; object-fit: cover;">
</body>
</html>
<html>
<body style="background-color: lightyellow; padding: 0; margin: 0; display: flex; justify-content: center; align-items: center; height: 100vh">
    <img src="clinteastwood.gif" style="height: 200px; width: 100%; object-fit: contain;">
</body>
</html>

UnexpectedGrit-dev-pic4

Build Release and Build Debug modes work correctly, but discovered element WebView will throw an exception, but NOT every time. I managed to capture the following error message and call stack...

System.ObjectDisposedException

Message=Cannot access a disposed object.

Object name: 'Microsoft.Maui.Platform.MauiWebView'.

Call stack follows:

<--- SNIP --->

0xFFFFFFFFFFFFFFFF in Android.Runtime.RuntimeNativeMethods.monodroid_debugger_unhandled_exception	C#

0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5	C#

0x23 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:364,26	C#

0x2E in Java.Interop.JniPeerMembers.AssertSelf at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.cs:153,5	C#

0x1 in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualObjectMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:858,5	C#

0x12 in Android.Webkit.WebView.get_WebViewClient at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Webkit.WebView.cs:1388,6	C#

0xD in Microsoft.Maui.Handlers.WebViewHandler.DisconnectHandler at D:\a\_work\1\s\src\Core\src\Handlers\WebView\WebViewHandler.Android.cs:54,5	C#

0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IWebView,Android.Webkit.WebView>.OnDisconnectHandler at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:79,4	C#

0x13 in Microsoft.Maui.Handlers.ViewHandler.OnDisconnectHandler at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandler.cs:214,4	C#

0x2 in Microsoft.Maui.Handlers.ElementHandler.DisconnectHandler at D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:112,4	C#

0x20 in Microsoft.Maui.Handlers.ElementHandler.Microsoft.Maui.IElementHandler.DisconnectHandler at D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:130,5	C#

0x64 in Microsoft.Maui.Controls.Element.SetHandler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:919,6	C#

0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:864,11	C#

0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:2061,5	C#

0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:96,4	C#

0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:127,4	C#

0x36 in Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.UpdateContent at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Android\FrameRenderer.cs:354,4	C#

0x1 in Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.<>c.<.cctor>b__73_6 at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Android\FrameRenderer.cs:28,54	C#

0x21 in Microsoft.Maui.PropertyMapper<Microsoft.Maui.Controls.Frame,Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer>. at D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:172,6	C#

0x17 in Microsoft.Maui.PropertyMapper.UpdatePropertyCore at D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:47,4	C#

0x1D in Microsoft.Maui.PropertyMapper.UpdateProperties at D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:82,5	C#

0xE3 in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.Frame>.SetVirtualView at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\VisualElementRenderer.cs:290,4	C#

0x1B in Microsoft.Maui.Controls.Handlers.Compatibility.ViewHandlerDelegator<Microsoft.Maui.Controls.Frame>.SetVirtualView at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\ViewHandlerDelegator.cs:84,4	C#

0x15 in Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.Microsoft.Maui.IElementHandler.SetVirtualView at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Android\FrameRenderer.cs:405,4	C#

0x8B in Microsoft.Maui.Controls.Element.SetHandler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:922,6	C#

0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:864,11	C#

0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:2061,5	C#

0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:96,4	C#

0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:127,4	C#

0x83 in Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\Layout\LayoutHandler.Android.cs:41,5	C#

0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutViewGroup>.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:56,4	C#

0x8B in Microsoft.Maui.Controls.Element.SetHandler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:922,6	C#

0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:864,11	C#

0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:2061,5	C#

0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:96,4	C#

0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:127,4	C#

0x83 in Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\Layout\LayoutHandler.Android.cs:41,5	C#

0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutViewGroup>.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:56,4	C#

0x8B in Microsoft.Maui.Controls.Element.SetHandler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:922,6	C#

0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:864,11	C#

0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:2061,5	C#

0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:96,4	C#

0x2 in Microsoft.Maui.Platform.ElementExtensions.ToPlatform at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:127,4	C#

0x60 in Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent at D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:42,5	C#

0x1 in Microsoft.Maui.Handlers.ContentViewHandler.MapContent at D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:47,4	C#

0x21 in Microsoft.Maui.PropertyMapper<Microsoft.Maui.IContentView,Microsoft.Maui.Handlers.IContentViewHandler>. at D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:172,6	C#

0x17 in Microsoft.Maui.PropertyMapper.UpdatePropertyCore at D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:47,4	C#

0x1D in Microsoft.Maui.PropertyMapper.UpdateProperties at D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:82,5	C#

0xD1 in Microsoft.Maui.Handlers.ElementHandler.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:79,4	C#

0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IContentView,Microsoft.Maui.Platform.ContentViewGroup>.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:53,4	C#

0x2 in Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\ContentView\ContentViewHandler.Android.cs:26,4	C#

0x7 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.IContentView,Microsoft.Maui.Platform.ContentViewGroup>.SetVirtualView at D:\a\_work\1\s\src\Core\src\Handlers\View\ViewHandlerOfT.cs:56,4	C#

0x8B in Microsoft.Maui.Controls.Element.SetHandler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:922,6	C#

0x2 in Microsoft.Maui.Controls.Element.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\Element\Element.cs:864,11	C#

0x18 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler at D:\a\_work\1\s\src\Controls\src\Core\VisualElement\VisualElement.cs:2061,5	C#

0xB0 in Microsoft.Maui.Platform.ElementExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ElementExtensions.cs:96,4	C#

0x2 in Microsoft.Maui.Platform.ViewExtensions.ToHandler at D:\a\_work\1\s\src\Core\src\Platform\ViewExtensions.cs:44,4	C#

0xBD in Microsoft.Maui.Controls.Platform.Compatibility.ShellContentFragment.OnCreateView at D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellContentFragment.cs:145,4	C#

0x24 in AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ at C:\a\_work\1\s\generated\androidx.fragment.fragment\obj\Release\net6.0-android\generated\src\AndroidX.Fragment.App.Fragment.cs:2031,4	C#

0xD in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:363,5	C#

<--- END --->

Microsoft Visual Studio Professional 2022

Version 17.10.1

VisualStudio.17.Release/17.10.1+34928.147

Microsoft .NET Framework

Version 4.8.09037

Installed Version: Professional

ADL Tools Service Provider 1.0

This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.10.338.1105

ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.10.338.1105

Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0

Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.10.338.1105

Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0

Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.10.0-3.24270.2+e8f775c1d8a73dee7ad02408712d714251e708ea

C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10

Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 17.0.24064.1

Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus 1.4.39 (main@e8108eb)

Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

GitHub Copilot 0.2.889.30432

GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Microsoft Azure Hive Query Language Service 2.6.5000.0

Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0

Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9

Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0

Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.10.8 (a565b86)

Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.10.0

NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Python - Profiling support 17.0.24064.1

Profiling support for Python projects.

Python with Pylance 17.0.24064.1

Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core) 17.10.3.2427201+4f57d1de251e654812adde201c0265a8ca7ca31d

Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.10.171.4

Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0

Hosting json editor into a tool window

TypeScript Tools 17.0.30327.2001

TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.10.0-3.24270.2+e8f775c1d8a73dee7ad02408712d714251e708ea

Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.10.0-beta.24228.1+dd749058c91585e9b5dae62b0f8df892429ee28f

Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2

AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0

Information about my package

VisualStudio.Mac 1.0

Mac Extension for Visual Studio

VSPackage Extension 1.0

VSPackage Visual Studio Extension Detailed Info

Xamarin 17.10.0.110 (main@cf2e960)

Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.10.3.10 (remotes/origin/d17-10@3beef58f89)

Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14)

Xamarin.Android Reference Assemblies and MSBuild support.

Mono: d9a6e87

Java.Interop: xamarin/java.interop/d17-5@149d70fe

SQLite: xamarin/sqlite/3.40.1@68c69d8

Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,231 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more