c# - COM 互操作,创建 .net com 并在 .net 中使用
问题描述
我有一个公开 com 接口的程序集:
[ComVisible(true)]
[Guid("C92A5F13-088F-4776-A967-42A60EFAFC29")]
public interface ITestInterface
{
byte[] AddItem(string label, byte[] array);
}
和实施:
[ComVisible(true)]
[Guid("C35C9235-3377-44A7-AC9E-7FCC24EF71D0")]
public class Test : ITestInterface
{
public byte[] AddItem(string label, byte[] array)
{
return null;//irrelevant
}
}
该 com 在程序集的清单中发布。
现在在客户端(.net),我有一个界面:
public interface ITestInterface
{
byte[] AddItem(string label, byte[] array);
}
并尝试激活它:
Type adapter = Type.GetTypeFromProgID("Test.Test");
object adapterObj = Activator.CreateInstance(adapter);
ITestInterface myClassAdapter = (ITestInterface)adapterObj;
在最后一行我得到异常:
System.InvalidCastException: 'Unable to cast object of type 'Test.Test' to type 'Test.ITest'.'
我的“客户端”界面有什么问题。我应该改变什么?
解决方案
推荐阅读
- javascript - 我想使用 javascript 动态创建标签
- reactjs - 动作的调度是否在反应流的后台运行?
- excel - 使用excel公式为超过2个空格的文本创建缩写
- elasticsearch - elasticsearch排序搜索返回中的_doc是什么意思?
- javascript - 如何在 Vue.js 中将带有一些数组对象值的 Post 请求发送到我的后端
- mysql - 如何在 SQL 中将 2 列合并为 1 列 TO 输出
- python - pandas - 如何在行中搜索整个单词
- python - 登录时重新加载计数对象
- db2 - 如何使 V_SQL 与包含 where 子句的字符串值连接。而不是表别名?在 DB2 中
- ionic-framework - 对 ionic 中的 FCM 和 Push 插件感到困惑