InvalidCastException when calling method from delphi-object in .net-Plugin

Hi,

in our scenario we are using a delphi host and a .net plugin. The plugin is implemented as class factory, that means all plugin-methods return references on .net-objects. All the interfaces inherit from IHYCrossPlatformInterface. This mechanism is working very stable for a long time.

Now we have the following problem:
When we call a .net-object method from Delphi and pass an delphi-object as argument, we cannot call any method of this delphi-object from .net.

We get a InvalidCastException:

Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘MyInterface’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}’ failed due to the following error: Schnittstelle nicht unterstützt (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))

The delphi-object implements IHYCrossPlatformInterface and the custom interface MyInterface and inherits from THYFakeIDispatch.

Is it possible to do calls back to delphi code this way or is casting the host property the only way?

Thanks,
Manuel

hundeggersoftware said: We get a InvalidCastException:
Do you use threads? Usually this exception is thrown when you trying to call object that was created in one thread from another one.

If you do, please take a look at the following article: Documentation | RemObjects Software

If you don’t, then can you please send us a small testcase that reproduces that problem? You can attach it here or send it to support@remobjects.com.

hundeggersoftware said: Is it possible to do calls back to delphi code this way or is casting the host property the only way?
There is no such limitation, you should be able to work with interfaces that you pass as a parameter.

This article hotlink is invalid. how get the solution? thanks.

Hello

It is https://docs.hydra4.com/HowTos/PassingInterfacesBetweenHostAndPlugins/

I cannot provide you a direct link to the ‘Interfaces and threads’ subsection, so you’ll need to scroll the article down.

Regards