Skip to content

Marshal.GetComInterfaceForObject in NativeAOT #114773

Open
@tfenise

Description

@tfenise

[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr GetComInterfaceForObject(object o, Type T)
{
ArgumentNullException.ThrowIfNull(o);
ArgumentNullException.ThrowIfNull(T);
return ComWrappers.ComInterfaceForObject(o, T.GUID);
}
[SupportedOSPlatform("windows")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IntPtr GetComInterfaceForObject(object o, Type T, CustomQueryInterfaceMode mode)
{
throw new NotSupportedException(SR.PlatformNotSupported_ComInterop);
}
[SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject<T, TInterface>([DisallowNull] T o)
{
return GetComInterfaceForObject(o!, typeof(T));
}

Line 96 should use typeof(TInterface) instead of typeof(T). Compare to

[SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject<T, TInterface>([DisallowNull] T o)
=> GetComInterfaceForObject(o!, typeof(TInterface), CustomQueryInterfaceMode.Allow);

In addition, it seems inconsistent that in the NativeAOT version, GetComInterfaceForObject(object o, Type T, CustomQueryInterfaceMode mode) throws unconditionally, but GetComInterfaceForObject(object o, Type T) may still work (with the help of ComWrappers.RegisterForMarshalling).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions