How to make properties visible to COM in a .NET DLL (Methods DO work)

只谈情不闲聊 提交于 2019-12-02 22:20:07

问题


Solved, see comments!

I have a simple .NET DLL written in c#.

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.

Here's the sample code:

[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
    {
    }
}

Here's the server-side script:

Set com = Server.CreateObject("ns.Com")    // WORKS
com.MyProperty = "abc"                    // GIVES ERROR
com.MyFunction                            // WORKS

I get the following error-message:

Microsoft VBScript Runtime Error "800a01b6'

Object Doesn't Support This Property or Method: MyProperty

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?


回答1:


Properties must be included in the interface definition to make them visible to COM.

Example:

[Guid("... some GUID ...")]
[ComVisible(true)]
public interface MyClassInterface
{
    string MyProperty { get; set; }
    bool MyMethod();
}


来源:https://stackoverflow.com/questions/37207659/how-to-make-properties-visible-to-com-in-a-net-dll-methods-do-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!