0

I have created COM interface with read/write properties:

[
    object,
    uuid(...),
    dual,
    pointer_default(unique)
]
IInterfaceWithProperty : IDispatch
{
     [propget, id(1)] HRESULT Property([out, retval] IInterface2** ppObject); 
     [propput, id(1)] HRESULT Property([in] IInterface* pObject); 
};

And when tried to use in in C#:

var value = object.Property;
object.Property = value;

got the following error:

error CS1545: Property, indexer, or event 'IInterfaceWithProperty .Property' is not supported 
by the language; try directly calling accessor methods 
'IInterfaceWithProperty.get_Property()' or 
'IInterfaceWithProperty.set_Property(IInterface)'

What could be the reason?

1
  • IInterface2 != IInterface. While that is valid in IDL, there are not a lot of languages that support this. I can't think of any. Other than C#, it allows you to work around that mistake by using the get and set accessor methods directly. Just like the error message says. Commented Sep 13, 2018 at 13:57

1 Answer 1

1

The reason of the error was that property should have the same type in getter and setter.

After changing IInterfaceWithProperty to

[
    object,
    uuid(...),
    dual,
    pointer_default(unique)
]
IInterfaceWithProperty : IDispatch
{
     [propget, id(1)] HRESULT Property([out, retval] IInterface2** ppObject); 
     [propput, id(1)] HRESULT Property([in] IInterface2* pObject); 
};

the problem disappeared.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.