Using InvokeMethod and GetPropertyValue

Class library usage, coding and language questions.
Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Using InvokeMethod and GetPropertyValue

Post by Marianne Jacobsen » Wed Jul 09, 2008 12:19 pm

I'm having trouble understanding how InvokeMethod and GetPropertyValue works.

I'm testing on 3rd party controls and enjoy the feature of calling custom methods and properties. Nevertheless I've run into some problems - some methods/properties simply return null. The reason for this is unclear to me and the Ranorex documentation does not provide much help.

I'm calling a property named Items but it returns null. I've set ErrorAsException to true but I get no exception - which may indicate that the property is actually null (even though I don't think it is). But if I try to call it with "get_Items" using InvokeMethod I get an InvalidOperationException with the message "The control does no longer exist." but it does. I can click it, see it and check other properties just fine.

Some information would be appreciated. Thanks for your time.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Thu Jul 10, 2008 4:35 pm

The problem is that these methods cross process boundaries and therefore the parameters and return values need to be serializable, i.e. transferable between process boundaries. The GetPropertyValue and InvokeMethod methods will return null if the returned value is not serializable. All primitive types (like int, double, string, …) are serializable and all classes marked with the Serializable attribute. For all other return types you need to provide some way to make the wanted data serializable.

With Ranorex 1.4 the only way was to provide a helper method in the control you want the data from. However, that often implies a change request to the control developer which often takes some time and sometimes isn't even possible.

That's why with Ranorex 1.5 we introduced a new way that does not imply a code change to the automated control: the Control.InvokeRemotely method. Using the Control.InvokeRemotely method one can define a delegate in the Ranorex code that is executed in the process of the automated control. This delegate should collect the wanted data and needs to return it in a serializable format (e.g. as a list of strings or integers).

I will write a Ranorex blog entry next week that will provide an example on how to use the Control.InvokeRemotely method - just in case the API documentation is not clear enough :)

Regards,
Alex
Ranorex Support Team

Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Post by Marianne Jacobsen » Mon Jul 14, 2008 9:34 am

Thank you very much for the extensive explanation - it's very appreciated.

I'm pretty sure that the Serializable attribute is why I get null when invoking the custom methods/properties.

I look forward to your blog entry.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Mon Jul 14, 2008 10:39 am

I just finished the blog post, you can find it here:
http://www.ranorex.com/blog/transfering ... et-control

Alex
Ranorex Support Team

Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Post by Marianne Jacobsen » Mon Jul 14, 2008 11:36 am

I see that it has been posted. Thank you very much.