-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Although Marshal.StringToBStr et al. works fine on Mac. The following code
delegate void Callback([MarshalAs(UnmanagedType.BStr)]string s);
[DllImport("libTestDynLib.dylib")]
static extern void MyTest([MarshalAs(UnmanagedType.BStr)]string s, Callback c);
static void Main(string[] args)
{
MyTest("This is a test", s =>
{
Console.WriteLine(s);
});
}
Is failing on Mac:
System.Runtime.InteropServices.MarshalDirectiveException: "Cannot marshal 'parameter dotnet/coreclr#1': Invalid managed/unmanaged type combination (String parameters and return types must be paired with LPStr, LPWStr, or LPTStr)."
at TestBSTR.Program.MyTest(String s, Callback c)\n at TestBSTR.Program.Main(String[] args) in /Users/odhanson/Projects/MyGuidTest/TestBSTR/Program.cs:15
Seems like (for looking at the code) this has only been implemented for windows (as part of COM support).
We are currently in the process of porting a FX application to Core, that has extensive interop with existing native libraries (that are cross platform). The BSTR is used extensively and we would definitely need support for this type of marshaling.