How to make properties visible to COM in a .NET DLL (Methods DO work)(如何使 .NET DLL 中的属性对 COM 可见(方法有效))
问题描述
已解决,见评论!
我有一个用 c# 编写的简单 .NET DLL.
I have a simple .NET DLL written in c#.
在 asp-classic 或 VB.NET 中,我可以毫无问题地创建对象并调用 DLL 中的成员函数.但是,这是我的绊脚石,我无法访问类属性.
In asp-classic or VB.NET i can create the object and call a member function in the DLL without any problem. But, and this is my stumbling point, i can't access class properties.
示例代码如下:
[Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IComEvents))]
public class Com : IComInterface
{
public string MyProperty{ get; set; } // <-- NOT ACCESSIBLE
public void MyFunction() // <-- ACCESSIBLE
{
}
}
这是服务器端脚本:
Set com = Server.CreateObject("ns.Com") // WORKS
com.MyProperty = "abc" // GIVES ERROR
com.MyFunction // WORKS
我收到以下错误消息:
Microsoft VBScript 运行时错误800a01b6"
Microsoft VBScript Runtime Error "800a01b6'
对象不支持此属性或方法:MyProperty
Object Doesn't Support This Property or Method: MyProperty
谁能告诉我,为什么我可以调用函数'MyFunciton',但是如果我想设置属性值,我得到了上面的错误?
Can anybody tell me, why i can call the function 'MyFunciton', but if i want to set the property-value, i get the error above?
推荐答案
属性必须包含在接口定义中以使它们对 COM 可见.
Properties must be included in the interface definition to make them visible to COM.
例子:
[Guid("... some GUID ...")]
[ComVisible(true)]
public interface MyClassInterface
{
string MyProperty { get; set; }
bool MyMethod();
}
这篇关于如何使 .NET DLL 中的属性对 COM 可见(方法有效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 .NET DLL 中的属性对 COM 可见(方法有效)
基础教程推荐
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
