dotnet / dotnet/runtime

[GeneratedComInterface] Does not handle the case where SizeParamIndex refers to an out parameter

Open
#120,389 2 comments 0 reactions 0 assignees View on GitHub
area-System.Runtime.InteropServices
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

Simple repro:

```c#
[Guid("00000000-0000-0000-0000-000000000013"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), GeneratedComInterface]
public partial interface ISizeParamIndexProblem
{
unsafe void SizeParamIndex([Out][MarshalAs(UnmanagedType.I4, SizeParamIndex = 1)] int[] elements, out uint size);
}
```

Compiling this gives:
> error SYSLIB1052: The specified 'MarshalAsAttribute' configuration for parameter 'elements' is not supported by source-generated COM. If the specified configuration is required, use `ComImport` instead. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1052)

This "worked" with ComImport ... or at least cswin32 is generating this code for methods like https://learn.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-psgetshader, and ComImport didn't complain. I'm not sure if it worked at runtime.

### Reproduction Steps

See above.

### Expected behavior

Ideally this works or, if not, give some hooks so a custom marshaler could do this?

### Actual behavior

Gives an error.

### Regression?

_No response_

### Known Workarounds

_No response_

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.