You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 7.0 WinForms中无法复制Guna控件的问题求助

.NET 7 WinForms复制Guna控件时COM报错解决方法

问题场景

在.NET 7.0 WinForms项目中使用Guna.UI2控件包,创建按钮后执行复制操作时触发错误:

执行此命令时出错。内置COM已通过功能开关禁用
(原错误提示:An error occurred while processing this command. built-in com has been disabled via a feature switch)

项目文件代码:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net7.0-windows</TargetFramework>
        <RootNamespace>Create_Effect_.NET_7._0</RootNamespace>
        <Nullable>enable</Nullable>
        <UseWindowsForms>true</UseWindowsForms>
        <ImplicitUsings>enable</ImplicitUsings>
        <PublishAot>true</PublishAot>
        <_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>
        <PublishTrimmed>false</PublishTrimmed>
        <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Guna.UI2.WinForms" Version="2.0.4.4" />
        <PackageReference Include="WinFormsComInterop" Version="0.4.3" />
    </ItemGroup>

</Project>

错误截图:
错误截图

解决步骤

  1. 移除项目中的WinFormsComInterop包引用:
    直接删除项目文件中<PackageReference Include="WinFormsComInterop" Version="0.4.3" />这一行,或在NuGet包管理器中卸载该包。
  2. 保存项目文件并重新生成项目。
  3. 再次尝试复制Guna控件操作。

原因说明

.NET 7.0及以上版本的WinForms已内置COM互操作支持(通过BuiltInComInteropSupport启用),而WinFormsComInterop是针对.NET 5/6等旧版本的兼容包,两者同时使用会触发内置COM支持被禁用的冲突,导致控件复制操作失败。

内容的提问来源于stack exchange,提问作者duy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 17:03:20