在 C# 中创建自定义任务窗格获取无法创建指定的 ActiveX 控件运行时错误

Create custom task pane in c# gets Unable to create specified ActiveX control runtime error

我使用 excel-dna 创建了一个简单的自定义任务窗格,它在“.dna”文件中包含一个组合框和一个按钮。但是当我将我的代码移动到“.cs”文件时,我在这行代码上收到 "Unable to create specified ActiveX control" 运行时错误:

ctp = CustomTaskPaneFactory.CreateCustomTaskPane(typeof(MyUserControl), "My Super Task Pane");。

我的原始代码类似于“https://github.com/KevinT/ExcelDna/blob/master/Distribution/Samples/CustomTaskPane.dna”。

谢谢。

我需要像这样在我的用户控件上添加 [ComVisible(true)]:

[ComVisible(true)]
public class MyUserControl : UserControl
{
}