c# - RegAsm.exe 遇到问题
问题描述
目前我正在遵循这个程序:
- 创建一些 C# 类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace TestAgain
{
public class Test
{
void testIt() {
MessageBox.Show("Yellow world");
}
}
}
- 签署项目。
- 在 AssemblyInfo.cs 中设置
[assembly: ComVisible(false)]
为[assembly: ComVisible(true)]
. - 构建项目。
- 运行 regasm
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" -tlb -codebase "C:\Users\sancarn\Desktop\tbd\TestAgain\TestAgain\bin\Debug\TestAgain.dll" -verbose
regasm 的输出如下:
Microsoft .NET Framework Assembly Registration Utility version 4.7.3056.0
for Microsoft .NET Framework version 4.7.3056.0
Copyright (C) Microsoft Corporation. All rights reserved.
Types registered successfully
Type 'TestAgain.Test' exported.
Assembly exported to 'C:\Users\sancarn\Desktop\tbd\TestAgain\TestAgain\bin\Debug\TestAgain.tlb', and the type library was registered successfully
所以类型TestAgain.Test
被导出并且类型库已经被注册。伟大的!
所以我去 Excel-VBA 并使用以下方法对其进行测试:
Sub testIt()
Dim o As Object
Set o = CreateObject("TestAgain.Test")
Call o.testIt
End Sub
并得到错误Error 429: ActiveX component can't create object
。IE 没注册?
有没有人知道为什么这不起作用?
注意:我之前已经设法获得了一个带有接口的 Com-Visible 应用程序,但我一直在寻找一种更简洁的方法,一位用户告诉我 regasm 可以完成这项工作。
解决方案
我已经知道这一点,但它溜走了我的脑海:
- 只有公共方法对 COM 公开。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace TestAgain
{
public class Test
{
public void testIt() {
MessageBox.Show("Yellow world");
}
}
}
这就像一个魅力。
推荐阅读
- angular - 如果在变量上使用 _.isObject(),Typescript 会忽略显式声明的 ANY 类型并将变量视为类型对象,从而导致属性名称错误
- sql - SQL Server 解密选项
- java - 拆分功能在 Recyclerview 适配器中无法正常工作
- java - 对我当前的 MVVM android 应用架构的建议
- jquery - 禁用提交按钮,直到所有字段都被填写
- java - For循环在Java中没有给出任何输出
- javascript - 获取本月的最后一个星期日 - JavaScript
- python - Tkinter - SyntaxError:关键字arg之后的非关键字arg
- python - 在 numba 中调用矢量化函数
- firebase - 部署单个函数时部署哪些文件?