Skip to content

Invalid cast from 'WinRT.IInspectable' to 'IMemoryBufferByteAccess' (GeneratedComInterface) #1672

@lostmsu

Description

@lostmsu

It's basically this issue, but it only happens when I replace [ComImport] with [GeneratedComInterface].

Describe the bug
Given

[GeneratedComInterface]
[Guid("5B0D3235-4DBA-4D44-865E-8F1D0E4FD04D")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public unsafe partial interface IMemoryBufferByteAccess
{
    void GetBuffer(out IntPtr buffer, out uint capacity);
}

Attempting to convert IMemoryBufferReference reference to IMemoryBufferByteAccess fails with

System.InvalidCastException: 'Invalid cast from 'WinRT.IInspectable' to 'ChatGPT.Platforms.Windows.Core.IMemoryBufferByteAccess'.'

To Reproduce
See the linked issue

  1. IMemoryBufferReference reference = ...
  2. reference.As<IMemoryBufferByteAccess>()

Expected behavior
Should get IMemoryBufferByteAccess

Version Info
.NET SDK 8.0 - net8.0-windows10.0.22621.0

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions