Skip to content

[Mono]: DllImport using MarshalAs and SizeParamIndex set to an enum parameter not implemented #116154

Open
@rene-descartes2021

Description

@rene-descartes2021

Description

When using an enum for a SizeParamIndex using Mono runtime, the following exception will be thrown:

MarshalDirectiveException: Array size control parameter must be an integral type.

In src/tests/ I searched for SizeParamIndex and found no test which used an enum for it.

EDIT: I think related is #35225 which covers interop tests which fail in Mono runtime but pass in CoreCLR, but a test doesn't currently exist for this enum issue.

Background context

I found this problem when building and running OmniSharp, which surfaces there in the use of microsoft/MSBuildLocator. Relevant MSBuildLocator code here:
https://github.com/microsoft/MSBuildLocator/blob/0bbf4988996176904ecc0dabb73165919fac605f/src/MSBuildLocator/NativeMethods.cs#L32

Reproduction Steps

Modify a test to use an enum for SizeParamIndex and test on Mono runtime.

Expected behavior

No exception. microsoft/MSBuildLocator wrote in issues that Mono isn't supported, it works fine on CoreCLR.

Actual behavior

See above MarshalDirectiveException.

Regression?

No response

Known Workarounds

No response

Configuration

dotnet core compiled with --use-mono-runtime.
On Android using Termux.

Other information

I think it is a one line fix, add case MONO_TYPE_ENUM to the switch here:

switch (m->sig->params [param_num]->type) {
case MONO_TYPE_I1:
case MONO_TYPE_U1:
case MONO_TYPE_I2:
case MONO_TYPE_U2:
case MONO_TYPE_I4:
case MONO_TYPE_U4:
case MONO_TYPE_I:
case MONO_TYPE_U:
case MONO_TYPE_I8:
case MONO_TYPE_U8:
break;
default: {
char *msg = g_strdup ("Array size control parameter must be an integral type.");

And add a SizeParamIndex test which uses an enum.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions