Skip to content

Interop Generators don't warn when CountElementName for parameter array is an out parameter #87081

@jtschuster

Description

@jtschuster

In the example below, the widths and length parameter will be used for marshalling the array, but they are not guaranteed to be set before the method is called. This would lead to a zero length array being marshalled.

        [LibraryImport("Doesn't Exist")]
        public static partial void Method(
                [MarshalUsing(CountElementName = nameof(length)),
                MarshalUsing(ElementIndirectionDepth = 1, CountElementName = nameof(widths))]
                int[][] array,
                [MarshalUsing(CountElementName = nameof(length))]
                out int[] widths,
                out int length);

The behavior of the generators should be the following:

Array parameter refKind / attribute
Length(s) parameter refKind / attribute
(nothing) ref in out [In, Out] [In] [Out]
(nothing) Ok Ok Ok Ok Ok Ok Ok
ref Ok Ok Ok Ok Ok Ok Ok
in Ok Ok Ok Ok Ok Ok Ok
out Warn Warn Warn Ok Warn Warn Ok
[In, Out] Ok Ok Ok Ok Ok Ok Ok
[In] Ok Ok Ok Ok Ok Ok Ok
[Out] Warn Warn Warn Ok Warn Warn Ok

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions