如何使属性对.NET DLL中的COM可见(方法可以正常工作) [英] How to make properties visible to COM in a .NET DLL (Methods DO work)

查看:109
本文介绍了如何使属性对.NET DLL中的COM可见(方法可以正常工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


已解决,请参见注释!

Solved, see comments!

我有一个用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可见(方法可以正常工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆