Skip to content

Remove temporary memory-safety LangVersion=preview overrides when no longer required #13085

Open

Description

@simonrozsival

Android framework version

Other - repository build configuration; not a customer application framework issue.

Affected platform version

The repository SDK/compiler once its normal, non-preview language-version policy supports memory-safety rules v2 and the migrated syntax. A .NET SDK major-version bump alone does not establish that support.

Description

Remove the temporary LangVersion=preview requirement as soon as the repository compiler supports the affected code under the normal language-version policy, without disabling the updated memory-safety model.

Originally requested by @jonathanpeppers in this review comment. Earlier related migrations include #13070, #13078, and #13189.

Progress as of 2026-11-25

Substantial unsafe-audit and v2 adoption work has landed:

  • #13440: NativeAOT caller-unsafe memory-safety rules - merged.
  • #13375: updated memory-safety rules in managed tooling - merged.
  • #13539: Mono.Android memory-safety rules v2 - merged.
  • #13735: Java.Interop test library opt-in - merged.
  • #13736: Mono.Android runtime test opt-in - merged.
  • #13737: binding test app and fixture-library opt-ins - merged.

Repository-wide consolidation is in #13734, which is still open as of this update. It puts the shared v2/preview defaults in the root Directory.Build.props and removes redundant project-local declarations. It does not establish that preview can already be removed.

Cleanup locations after consolidation

On the current #13734 branch, the remaining tracked preview declarations are:

  • Directory.Build.props: the shared, conditional LangVersion=preview default beside MemorySafetyRulesVersion=2. Its comment now links to this issue.
  • tools/workload-dependencies/workload-dependencies.csproj: an explicit override for the owned tool whose local props intentionally bypass the root configuration.

These are the expected starting points after #13734 merges, not an exhaustive or permanently fixed inventory. Until then, main can still contain the project-local settings that the PR removes. Search the actual tree when doing the cleanup; the earlier external/Java.Interop/... path and original three-project list are no longer a useful current inventory.

Generated customer templates deliberately do not carry either compiler setting. The shared Arcade package-restore bootstrap is also outside this rollout and keeps its own defaults.

Completion criteria

  • The pinned repository compiler accepts the affected syntax and memory-safety rules v2 under the normal non-preview language policy. Do not assume a particular SDK major version or future numbered C# version is sufficient.
  • Audit all applicable preview declarations, starting with the root default and isolated owned tooling. Remove those no longer required and inherit the normal repository language policy; do not replace them with permanent project-local language-version pins.
  • Preserve MemorySafetyRulesVersion=2 and its effective activation. Preview language mode and memory-safety activation are separate decisions: removing preview must not silently revert callers to the older rules or weaken caller-unsafe API rejection. The earlier updated-memory-safety-rules feature-switch spelling is not the current configuration to blindly copy.
  • Verify evaluated settings and actual compiler arguments for the affected projects/configurations/frameworks. A file's presence or a successful dependency build alone does not prove that every consumer compiled with the intended rules.
  • Affected projects and relevant existing tests pass, including the JNI/runtime and generator/tooling coverage required by the changes. Preserve product API contracts and safe-caller rejection of caller-unsafe APIs.

Steps to Reproduce

  1. Use the compiler pinned by the current repository and inspect the actual preview settings:

    git grep -n 'LangVersion.*preview' -- '*.props' '*.targets' '*.csproj'
  2. Try the normal non-preview language mode on affected code while preserving the memory-safety opt-in. For example:

    ./dotnet-local.sh build src/Java.Interop/Java.Interop.csproj -c Debug -p:LangVersion=latest
  3. Check effective MemorySafetyRulesVersion/LangVersion values and the Csc task arguments, then run the relevant existing builds and tests. The compiler prerequisite, rather than a hard-coded SDK/version assumption, determines when this issue can be completed.

Did you find any workaround?

Keep the temporary preview requirement in the shared repository configuration and isolated owned tooling until the compiler prerequisite is satisfied. Do not reintroduce preview settings into generated customer projects or the shared Arcade restore scaffold.

Relevant log output

Historical evidence from SDK 12.0.100-alpha.1.26523.103, recorded when the temporary overrides were introduced:

  • CS8652: updated memory-safety rules require the preview language version.
  • CS1617: that compiler rejects LangVersion=16 and lists numbered versions only through C# 15.

These observations explain the original override; they are not permanent restrictions or a substitute for checking the compiler pinned when cleanup is attempted.

Activity

  1. added
    needs-triage
    on Oct 12, 2026
  2. changed the title [-]Remove memory-safety LangVersion=preview overrides when C# 16 is the default[/-] [+]Remove temporary memory-safety LangVersion=preview overrides when no longer required[/+] on Oct 29, 2026
  3. removed
    needs-triage
    on Nov 19, 2026
  4. added this to the .NET 12 milestone on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions