3

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?

Community
  • 1
  • 1
rudy
  • 185
  • 2
  • 11
  • 4
    Are you aware the fields and properties are very different things in .NET? Calling a property a field is actually incorrect in .NET terminology. I edited your title to reflect the content of your question, but you've changed it back. You are talking about properties, not fields, so shouldn't the title of your question reflect that? http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c – spender May 13 '16 at 10:35
  • No, i wasn't, thanks a lot for that! I haven't completely realized, that an interface can have properties, but not fields...! Thanks again - question solved:) – rudy May 13 '16 at 10:45
  • 2
    Correct terminology FTW! – spender May 13 '16 at 10:48
  • What is the answer to this then? I don't see anything in the comments which actually answers the question. – StayOnTarget May 05 '17 at 19:34

1 Answers1

3

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();
}
George
  • 1,111
  • 3
  • 20
  • 38