Skip to content

[marshal methods] Make AndroidEnvironmentInternal.UnhandledException public#10775

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-unhandled-exception-crash
Draft

[marshal methods] Make AndroidEnvironmentInternal.UnhandledException public#10775
Copilot wants to merge 5 commits intomainfrom
copilot/fix-unhandled-exception-crash

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

Summary

Fixes issue #10602 where marshal method wrappers would crash with MethodAccessException when calling Android.Runtime.AndroidEnvironmentInternal.UnhandledException().

Changes

Note: Removed [DebuggerBrowsable] attributes as they are only valid on properties, indexers, and fields - not on types or methods.

Original prompt

This section details on the original issue you should resolve

<issue_title>Crashes with Method Android.Runtime.AndroidEnvironmentInternal.UnhandledException(System.Exception) is inaccessible (...) exception</issue_title>
<issue_description>### Android framework version

net9.0-android

Affected platform version

MAUI 9.0.110

Description

For some time I've been noticing random crashes for some % of users with this stacktrace

System.MethodAccessException: Method `Android.Runtime.AndroidEnvironmentInternal.UnhandledException(System.Exception)' is inaccessible from method `AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle__mm_wrapper(intptr,intptr,intptr,intptr,intptr)'
   at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle__mm_wrapper(IntPtr jnienv, IntPtr native__this, IntPtr native_inflater, IntPtr native_container, IntPtr native_savedInstanceState)

Since it's happening in release mode and I can't reproduce it it's hard to say anything more about it.

Don't know how useful that would be but the first time I got a log with this error was on 06/17/2025 but I can't tell if it's due to some changes in MAUI/net-android or in my configuration

Steps to Reproduce

Did you find any workaround?

No response

Relevant log output

```</issue_description>

<agent_instructions>Can you fix this issue, where we just made the problematic class/method public?

To help prevent developers from using it, can you mark any newly public APIs:
```csharp
[DebuggerBrowsable (DebuggerBrowsableState.Never)]
[EditorBrowsable (EditorBrowsableState.Never)]

Add the test case from here:

Add to your commit message:

Co-authored-by: Marek Habersack <grendel@twistedcode.net>
```</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@grendello</author><body>
@OvrBtn the OP trace definitely suggests a connection to marshal methods (the `_mm_wrapper` prefix indicates a marshal methods wrapper in use), so that's at least one scenario.
As for your new release, can you attach here the `lib/arm64-v8a/libassemblies.arm64-v8a.blob.so` file from your apk, please?
It would also be useful to see the stack trace from the new version crash. Thanks!</body></comment_new>
<comment_new><author>@grendello</author><body>
@OvrBtn cool, thanks for the .so and the trace! I wanted to confirm that `Mono.Android.Runtime.dll` is packaged in your app, and it is. However, looking at the latest trace, you are still using marshal methods - otherwise we wouldn't see the `__mm_wrapper` suffix. Seems like something overrode your `<AndroidEnableMarshalMethods>false</AndroidEnableMarshalMethods>` setting? Build your app from a clean state (after removing `bin` and `obj`) and record a binlog (`-bl` command line parameter to `dotnet build`) and see what is the actual value of `AndroidEnableMarshalMethods` property.</body></comment_new>
<comment_new><author>@grendello</author><body>
@OvrBtn examine dll files in `obj/` in the latest build to see if they contain any methods with the `_mm_wrapper` suffix - there should be none.</body></comment_new>
<comment_new><author>@grendello</author><body>
@OvrBtn ok, then at least your local build behaves correctly. The next step would be to examine the CI binlogs and dll contents.</body></comment_new>
<comment_new><author>@grendello</author><body>
@OvrBtn Glad you found the issue in your latest release! The issue in OP is a real one and once the deities of CI decide that it's a good time and date for a green build, a fix will be in `main` soon.</body></comment_new>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 5, 2026 20:16
…odAccessException

Co-authored-by: Marek Habersack <grendel@twistedcode.net>

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: Marek Habersack <grendel@twistedcode.net>

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crashes due to inaccessible Android method [marshal methods] Make AndroidEnvironmentInternal.UnhandledException public Feb 5, 2026
Copilot AI requested a review from jonathanpeppers February 5, 2026 20:21
Co-authored-by: Marek Habersack <grendel@twistedcode.net>

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
jonathanpeppers

This comment was marked as outdated.

Co-authored-by: Marek Habersack <grendel@twistedcode.net>

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 5, 2026

@copilot

Removed the [DebuggerBrowsable] attributes in commit e9a4e22, keeping only [EditorBrowsable(EditorBrowsableState.Never)] on both the class and method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crashes with Method Android.Runtime.AndroidEnvironmentInternal.UnhandledException(System.Exception) is inaccessible (...) exception

2 participants