See the question and my original answer on StackOverflow

Build-in COM has been disabled for some reason in your project, maybe you use AOT or IL-trimming?

So, you can't use the "old" way of declaring interface or functions with attributes such as ComImport or DllImport, which rely on code generation at run time.

Instead, you want to use the new COM interop Source generator and define the interface like this instead, using the GeneratedComInterface attribute:

[GeneratedComInterface, Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")]
public partial interface ISwapChainPanelNative
{
    [PreserveSig]
    int SetSwapChain(IDXGISwapChain swapChain);
}

This will cause the source generator to build interop code at compile time.

PS: all this is only valid in a .NET 8 and higher context.