最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

winui 3 - Exception in ISwapChainPanelNative Only in Release Mode (C#) - Stack Overflow

programmeradmin1浏览0评论

I am developing a application in C#. I am using SwapChainPanel, but an exception occurs only in Release mode. Where is the switch mentioned in the error message? I referred to the URL, but I couldn't find it.

Error Message:

Built-in COM has been disabled via a feature switch. See for more information.

Here is the code where the error occurs:

ISwapChainPanelNative panelNative = MySwapChainPanel.As<ISwapChainPanelNative>();

And here is the definition of ISwapChainPanelNative:

[Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
internal interface ISwapChainPanelNative
{
    int SetSwapChain([In] IntPtr swapChain);
}

I am developing a application in C#. I am using SwapChainPanel, but an exception occurs only in Release mode. Where is the switch mentioned in the error message? I referred to the URL, but I couldn't find it.

Error Message:

Built-in COM has been disabled via a feature switch. See https://aka.ms/dotnet-illink/com for more information.

Here is the code where the error occurs:

ISwapChainPanelNative panelNative = MySwapChainPanel.As<ISwapChainPanelNative>();

And here is the definition of ISwapChainPanelNative:

[Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
internal interface ISwapChainPanelNative
{
    int SetSwapChain([In] IntPtr swapChain);
}
Share Improve this question edited Mar 13 at 8:07 kinton asked Feb 14 at 10:30 kintonkinton 3151 silver badge7 bronze badges 5
  • 1 Since build-in COM has been disabled for some reason (AOT?), you want to define it like this instead: [GeneratedComInterface, Guid("63aad0b8-7c24-40ff-85a8-640d944cc325")] public partial interface ISwapChainPanelNative { [PreserveSig] int SetSwapChain(IDXGISwapChain swapChain); } as shown here github/smourier/DirectNAot/blob/main/Samples/… – Simon Mourier Commented Feb 14 at 10:42
  • Thank you! The method you taught me worked perfectly! – kinton Commented Feb 16 at 23:38
  • @Simon Mourier In this case, should I ask the person who provided the solution to post their answer, or should I post my own answer to close the question? I always find myself unsure about this. If possible, I would appreciate it if you could post it as your answer. – kinton Commented Feb 17 at 0:02
  • 1 A comment like this is usually to check it works on your side, and prepares a future response. It would be impolite to post the answer as is yourself, unless you do significante adaptation or changes. At least that's my way of thinking :) – Simon Mourier Commented Feb 17 at 7:19
  • Thank you for your insight!That makes sense—I’ll keep that in mind for future cases. I appreciate the clarification. – kinton Commented Feb 18 at 2:40
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论