Skip to content

fix(tasks): resolve CS9377/CS9389 memory-safety errors in monodroid-nativeaot.cs - #134277

Open
omid-io wants to merge 2 commits into
dotnet:mainfrom
omid-io:fix/issue-134115-monodroid-cs9377-cs9389
Open

omid-io wants to merge 2 commits into
dotnet:mainfrom
omid-io:fix/issue-134115-monodroid-cs9377-cs9389

Conversation

@omid-io

@omid-io omid-io commented Sep 19, 2026

Copy link
Copy Markdown

Fixes #134115

Description

Under the updated memory safety rules (net11.0 / Roslyn preview diagnostics), src/tasks/AndroidAppBuilder/Templates/monodroid-nativeaot.cs failed to build for Android NativeAOT legs with:

  • CS9377: The 'unsafe' modifier does not have any effect on type declarations (MonoDroidExports, JNIEnv, JNINativeInterface, JavaVM).
  • CS9389: 'extern' member (AndroidCryptoNative_InitLibraryOnLoad and ManagedMain) must be marked 'unsafe' or 'safe'.

Changes

  • Removed obsolete unsafe modifiers from MonoDroidExports, JNIEnv, JNINativeInterface, and JavaVM type declarations.
  • Scoped unsafe directly to pointer-bearing JNI entry points and methods (SetEnv, InitRuntime, ExecEntryPoint, FreeNativeResources, GetStringUTFChars, GetJavaVM, GetArrayLength, GetObjectArrayElement).
  • Explicitly marked AndroidCryptoNative_InitLibraryOnLoad and ManagedMain as unsafe.

Verification

  • Validated with Roslyn C# syntax tree parser (LanguageVersion.Preview) with 0 diagnostics.
  • Verified AST structure and explicit unsafe modifier scoping across all affected declarations.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 19, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@omid-io

omid-io commented Sep 19, 2026

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 134277 in repo dotnet/runtime

This branch has not been deployed

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

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ci-scan] Build break: CS9377/CS9389 memory-safety errors in monodroid-nativeaot.cs block Android NativeAOT legs

1 participant