[API Proposal]: Platform-aware Marshal.StringToHGlobalUni equivalent #62475
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-Interop-coreclr
untriaged
New issue has not been triaged by the area owner
Background and motivation
As for now,
Marshal.StringToHGlobalUni
internally calls this:Thus, we have hardcoded UTF-16 here, which works as expected on Windows, but fails on Linux.
In cases of P/Invoke with
LPCWSTR
s inside structures like this, native code expects UTF-32:This is unobvious. Also, there are no such details in docs too. One converts string to Unicode, but what Unicode exactly?
API Proposal
API Usage
Alternative Designs
Probably, this will require some changes inside default string marshalling.
I mean, one can use proposed API with this struct:
but in case of this declaration:
we'll still get UTF-16 because of default marshalling settings.
Risks
No response
The text was updated successfully, but these errors were encountered: