admin管理员组文章数量:1414605
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 Answer
Reset to default 1Build-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.
本文标签: winui 3Exception in ISwapChainPanelNative Only in Release Mode (C)Stack Overflow
版权声明:本文标题:winui 3 - Exception in ISwapChainPanelNative Only in Release Mode (C#) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745194524a2647070.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
[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