Skip to content

Replace calls to Marshal.PtrToStringUni methods with Utf16StringMarshaller #118988

Open

Description

@xtqqczze
  • Replace calls to Marshal.PtrToStringUni and Marshal.StringToCoTaskMemUni with calls of equivalent methods on Utf16StringMarshaller throughout the repository.
  • Improve type consistency by updating method signatures and fields to use ushort* instead of IntPtr for UTF-16 string pointers, removing unnecessary (IntPtr) casts.
  • Add unsafe modifiers to fix unsafe context issues when using unmanaged pointers as appropriate.
  • Do not change interop tests.
  • Preserve original Utf16StringMarshaller.cs

cc: @copilot, @jkotas

Activity

  1. added
    untriaged
    on Aug 22, 2025
  2. dotnet-policy-service commented on Aug 22, 2025

    @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. removed
    untriaged
    on Aug 22, 2025
  4. added this to the 11.0.0 milestone on Aug 22, 2025
  5. added
    help wanted
    on Jul 13, 2026
  6. BekAllaev commented on Nov 18, 2026

    @BekAllaev
    Contributor

    Hi, I’d like to pick this up since the Copilot PR (#118997) was closed.

    As @jkotas pointed out there, most of this code is Windows-specific. I’ve already built the runtime on my Windows machine.

    I’m planning to go area by area with small PRs, starting with System.Net.NameResolution. For example, ai_canonname is declared as sbyte* in AddressInfo and as IntPtr in AddressInfoEx, while it is a PWSTR (a pointer to a UTF-16 string) in both native structs, so both can become ushort*.

    If that works, I’ll open a PR.

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

Metadata

Metadata

Assignees

Labels

area-Interop-coreclrhelp wanted

Type

No type

Projects

  • Status
    No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions