Skip to content

[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1, ArraySubType = UnmanagedType.LPUTF8Str)] results in "Cannot marshal 'parameter #3': Unknown error." #7315

Closed
@dlech

Description

@dlech

I am trying out the UTF8 pinvoke marshalling. I have the following that works as expected:

    [DllImport ("gio-2.0", CallingConvention = CallingConvention.Cdecl)]
    static extern bool g_application_id_is_valid([MarshalAs(UnmanagedType.LPUTF8Str)] string applicationId);

However, this one does not...

    [DllImport ("gio-2.0", CallingConvention = CallingConvention.Cdecl)]
    static extern void g_application_run (SafeApplicationHandle application,
        int argc, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1, ArraySubType = UnmanagedType.LPUTF8Str)] string[] argv);

It throws a MarshalDirectiveException with the message "Cannot marshal 'parameter dotnet/coreclr#3': Unknown error."

I see that in tests/src/Interop/StringMarshalling/UTF8/UTF8Test.cs, there is not a test for such a case, so I am guessing that perhaps it was overlooked and has not been implemented yet. (Or, if there is a mistake on my part, the error message could be improved.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions