Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeAnalyzer suggestion: Application subclasses must provide activation constructor #8410

Open
jonpryor opened this issue Oct 10, 2023 · 0 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Milestone

Comments

@jonpryor
Copy link
Member

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.), .NET Android (net7.0-android, etc.)

Affected platform version

All

Description

When subclassing Android.App.Application, the "Activation Constructor" (IntPtr handle, JniHandleOwnership transfer) must also be provided. Failure to do so will result in runtime errors:

#8399

Steps to Reproduce

  1. dotnet new android

  2. Add an Application subclass

    [Application]
    public class MyApp : Application {
    }
  3. run

This will crash, with adb logcat containing:

F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Unable to activate instance of type MyApp from native handle 0x7ff1f3b468 (key_handle 0x466b26f).

See also the Java Activation documentation:

There are two scenarios in which the (IntPtr, JniHandleOwnership) constructor must be manually provided on a Managed Callable Wrapper subclass:

  1. Android.App.Application is subclassed. Application is special; the default Application constructor will never be invoked, and the (IntPtr, JniHandleOwnership) constructor must instead be provided.

Did you find any workaround?

No response

Relevant log output

No response

@jonpryor jonpryor added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Oct 10, 2023
@jonathanpeppers jonathanpeppers added enhancement Proposed change to current functionality. and removed needs-triage Issues that need to be assigned. labels Oct 10, 2023
@jonathanpeppers jonathanpeppers added this to the .NET 9 Planning milestone Oct 10, 2023
@jonpryor jonpryor modified the milestones: .NET 9, .NET 10 Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Projects
None yet
Development

No branches or pull requests

3 participants