Skip to content

ComVariantMarshaller and ComVariant does not work well with Com interfaces #117041

Open
@m-celikba

Description

@m-celikba

Description

Consider this example:

[GeneratedComInterface, Guid(..)]
interface IComItf
{
    ...
}

[GeneratedComClass, Guid(..)]
class ManagedComItf : IComItf
{
    ...
}

then:

IComItf instNative = CreateNativeImplementation();
IComItf instManaged = new ManagedComItf();

var v1 = ComVariantMarshaller.ConvertToUnmanaged(instManaged); // works
var v2 = ComVariantMarshaller.ConvertToUnmanaged(instNative); // <--------------- does not work

because of this passing a com interface to a com method as object fails when the method has this signature:
void Method([MarshalUsing(typeof(ComVariantMarshaller))] object obj);

Additionally these are missing:

var v3 = ComVariant.Create(instNative);
var instManaged2 = v1.As<IComItf>();

PS:
this works but does not help:
var v4 = ComVariantMarshaller.ConvertToUnmanaged(new UnknownWrapper(instNative)); // works

Reproduction Steps

see description

Expected behavior

ComVariantMarshaller should be able to work directly with COM interfaces

Actual behavior

ComVariantMarshallers cannot be created from COM interfaces

Regression?

No response

Known Workarounds

No response

Configuration

.NET9

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions