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

Open
#116,154 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c, csharp

Research direction

Start with src/mono/mono/component/marshal-ilgen.c around lines 474-487, then inspect the existing SizeParamIndex tests under src/tests/. Run the relevant interop tests on the Mono runtime and add coverage using an enum parameter. Done means the test no longer raises MarshalDirectiveException and the interop test passes on Mono.

Written by the indexing model from the issue text.

Description

area-Interop-mono
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:
https://github.com/dotnet/runtime/blob/1713d65316467e3eaf23514b6642eba5869f1b70/src/mono/mono/component/marshal-ilgen.c#L474-L487

And add a SizeParamIndex test which uses an enum.

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.