In the COM interface generator and LibraryImport generator, we should be able to specify [NativeMarshalling(typeof(UniqueComInterfaceMarshaller<IFoo>))] to instruct the generators to use that marshaller. However, it doesn't override the default marshaller for COM interfaces.
In the example below, the marshalling of foo parameters should use UniqueComInterfaceMarshaller, but currently use ComInterfaceMarshaller.
[GeneratedComInterface]
[GUID(...)]
[NativeMarshalling(typeof(UniqueComInterfaceMarshaller<IFoo>))]
internal partial interface IFoo
{
string GetMessage();
void DoWorkTogether(IFoo foo);
}
public static class PInvokes
{
[LibraryImport("lib")]
bool TryGetFoo(out IFoo foo);
}
This shouldn't require changing code outside of src/libraries/System.Runtime.InteropServices.