You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Marshalling a struct containing a string field via P/Invoke fails when the string contains certain unicode characters. The following exception is thrown:
Unhandled exception. System.Runtime.InteropServices.COMException (0x8007007A): The data area passed to a system call is too small.
(0x8007007A)
at System.StubHelpers.ValueClassMarshaler.ConvertToNative(IntPtr dst, IntPtr src, IntPtr pMT, CleanupWorkListElement& pCleanupWorkList)
at Program.foo(Label label)
at Program.Main(String[] args) in /home/davorin/Razvoj/Concepts/Test/Program.cs:line 7
It seems the issue is only triggered when the string contains characters that occupy more than 2 bytes in UTF-16. It doesn't matter whether the struct is passed by value, by pointer or in an array.
Minimal test case:
using System.Runtime.InteropServices;classProgram{staticvoidMain(){
foo(new Label {Text="●"});}[DllImport("foo")]staticexternvoidfoo(Labellabel);[StructLayout(LayoutKind.Sequential)]structLabel{publicstringText;}}
// Compile as a shared library:// gcc -shared -o libfoo.so foo.cstructLabel {
constchar*text;
};
voidfoo(structLabellabel) {
}
The text was updated successfully, but these errors were encountered:
Affected versions: .NET Core 3.1
OS: Arch Linux, Buildroot
Marshalling a struct containing a string field via P/Invoke fails when the string contains certain unicode characters. The following exception is thrown:
It seems the issue is only triggered when the string contains characters that occupy more than 2 bytes in UTF-16. It doesn't matter whether the struct is passed by value, by pointer or in an array.
Minimal test case:
The text was updated successfully, but these errors were encountered: