Skip to content

[Servicing] Backport #124408 to .NET 10 — GetMarshalAs regression on SafeArrayUserDefinedSubType breaks reflecting COM-interop attributes #129889

Description

@vijujo

Description

The fix in #124408 (closes #124346, milestone 11.0.0) resolves a .NET 9/10 regression in
MetadataImport.GetMarshalAs. Could it be considered for a .NET 10 servicing backport? Both the issue
and the PR are locked, so I'm opening this as a separate servicing request rather than commenting there.

Why .NET 10 specifically: .NET 10 is the current LTS that teams are actively migrating to. The fix is
in 11.0.0 only; .NET 10.0.9 still has the regression, with no app-side workaround.

Impact: any unit test that mocks a tlbimp-generated COM interface (Moq / Castle DynamicProxy) throws
at proxy-creation time. Building the proxy enumerates each parameter's custom attributes, which hits
GetMarshalAs on members marshaled as
[MarshalAs(UnmanagedType.SafeArray, SafeArrayUserDefinedSubType = typeof(...))] — extremely common in COM
interop. The interop metadata is valid and Moq/Castle are already at their latest versions, so the only
mitigations today are to stay on .NET 8 / .NET Framework or to drop those test suites on the .NET 10 leg.

Thanks!

Reproduction Steps

Minimal repro (no tlbimp, ~30 lines): two assemblies — a struct MyUdt in assembly Udt, and an
interface in assembly Probe with
void SetItems([MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_RECORD, SafeArrayUserDefinedSubType = typeof(MyUdt))] MyUdt[] items);.
Calling GetCustomAttributes() on that parameter throws on .NET 9/10 and succeeds on .NET 8 and .NET 11.

Net10-SafeArray-MarshalAs-MinimalRepro.zip

Expected behavior

GetCustomAttributes() returns the MarshalAsAttribute, as on .NET 8 and .NET 11.

Actual behavior

Throws TypeLoadException (#124346) or FileLoadException: the given assembly name was invalid on .NET 9/10.

Regression?

Verified version matrix (identical source and compiled assemblies):

Runtime Result
.NET Framework 4.8 OK
.NET 8.0.28 OK
.NET 9.0.10 FAIL
.NET 10.0.9 FAIL
.NET 11.0.100-preview.7 OK (after #124408)

Known Workarounds

None (app-side); fix is #124408, in 11.0.0 only.

Configuration

.NET 10.0.9 / win-x64 / Windows 11.

Other information

#124346
#124408

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions