Open SupinePandora43 opened 3 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
@mavasani Do you have permissions on this repository to move this to dotnet/roslyn-analyzers?
I'm finding this is raised even if MarshalAs is LPStr.
[DllImport("mylib", CharSet = CharSet.Ansi, ExactSpelling = true, ThrowOnUnmappableChar = true)]
public static extern void Foo([MarshalAs(UnmanagedType.LPStr)] string s); // CA2102
The only way to satisfy the analyzer seems to be to marshal the string as unicode/utf16, which is not possible if the native API doesn't support that.
Example Input
Output
Steps To Reproduce
DllImport
Attribute andstring
argument[MarshalAs(UnmanagedType.LPUTF8Str)]
orCustomMarshaler
CA2101