Skip to content

[NET 11.0.0] Large P/Invoke string marshaling StackOverflowException still present (fix not in GA) #137601

Todo

Description

@JonPawley-Trimble

Description

#132243 reported a .NET 11 regression: P/Invoke DllImport string marshaling of large payloads (~5.5 MB) throws StackOverflowException under Release/FullOpts (works on .NET 10; works with larger thread stack / Debug / min-opts).

That issue was closed by #132536 (merged to main 2026-08-21). That PR was milestoned for 12.0-preview1 and does not appear to have been backported to release/11.0.

We are still reproducing the failure on .NET 11.0.0 GA (SDK 11.0.100).

Please consider backporting #132536 to release/11.0 for inclusion in the next .NET 11 servicing update.

Reproduction Steps

Same as #132243 (and the attached reproducer there). Minimal form:

using System.Runtime.InteropServices;

var s = new string('f', 5_500_000);

[DllImport("msvcrt", EntryPoint = "strlen")]
static extern int StrLen(string value);

Console.WriteLine(StrLen(s));

Run under .NET 11.0.0, Release, default JIT opts.

Also reproduces with SWIG-generated [DllImport] passing a ~5.5 MB managed string into native (same scenario as #132243).

Expected behavior

Call succeeds (marshal buffer uses heap fallback above the ~261-byte stack threshold), as on .NET 10 and as after #132536 on main.

Actual behavior

Immediate StackOverflowException in the P/Invoke stub before native entry (Release/FullOpts).

Regression?

Yes — from .NET 10. Originally reported against .NET 11 Preview 7; still present in 11.0.0 GA.

Known Workarounds

  • Increase thread stack size (e.g. ~10 MB), or
  • Stay on .NET 10 until a servicing fix ships.

Configuration

Output of dotnet --info:

.NET SDK:
 Version:           11.0.100
 Commit:            297acf930f
 Workload version:  11.0.100-manifests.5d612b92
 MSBuild version:   18.12.2-1.26529.118+297acf930

Other information

Root cause (per #132243 / #132536): JIT if-conversion speculated a guarded localloc past the 261-byte stack/heap check in the interop string marshalling stub. Fix marks GT_LCLHEAP with GTF_CALL | GTF_GLOB_REF.

Request: backport #132536 to release/11.0.

Activity

  1. added
    untriaged
    on Nov 15, 2026
  2. dotnet-policy-service commented on Nov 15, 2026

    @dotnet-policy-service
    Contributor

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

  3. added
    area-CodeGen-coreclr
    and removed on Nov 16, 2026
  4. dotnet-policy-service commented on Nov 16, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  5. added this to the 12.0.0 milestone on Nov 25, 2026
  6. removed
    untriaged
    on Nov 25, 2026
  7. JonPawley-Trimble commented on Nov 25, 2026

    @JonPawley-Trimble
    Author

    Does the adding of this to the 12.0.0 milestone indicate that this will not be back-ported to .NET 11?

  8. AaronRobinsonMSFT commented on Nov 26, 2026

    @AaronRobinsonMSFT
    Member

    @jakobbotsch @EgorBo I've created a backport to .NET 11, #138323. Let me know if you'd like to move it forward or you can take it over.

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

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions