I am trying to expose a C function which takes a UTF-8 string to C# (dotnet 5.0). I am getting a warning which does not make sense to me. Here is a simple way to reproduce it, using fopen(3):
[DllImport("libc.so.6", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr fopen([MarshalAs(UnmanagedType.LPUTF8Str)] string pathname, string mode);
Visual Studio 2019 is reporting a warning:
From the documentation, it seems I need to set CharSet.Ansi in my case:
and use UnmanagedType.LPUTF8Str:
What did I misunderstood from the documentation ?
