InvokeAction returning custom objects

Ask general questions here.
phaneendra
Posts: 7
Joined: Tue Sep 13, 2016 1:38 pm

InvokeAction returning custom objects

Post by phaneendra » Tue Oct 04, 2016 6:12 am

Hi Team,

I have a case here:

My UI element "A" has a public function as:

public CustomObject OpenedInstance() {
...............................
..............................
return customObject;
}

This returns an object of type CustomObject.

When I use this function from ranorex:

var custObj = .......InvokeAction("OpenedInstance");

The custObj here is of type object.

My question is: how could I get my original type "CustomObject" from this object type?

Br,
Phanee

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: InvokeAction returning custom objects

Post by krstcs » Tue Oct 04, 2016 1:29 pm

All object types in .NET derive from the base Object class, so an Object instance can hold any other object type. I would suggest doing some reading on .NET before you jump head-first into the pool. :D

To get your original object type back you need to cast the returned value like this:

Code: Select all

var custObj = .......InvokeAction("OpenedInstance");
CustomObject myCustObject = (CustomObject)custObj; //this tells .NET to remap the custObj to a new type
Shortcuts usually aren't...

phaneendra
Posts: 7
Joined: Tue Sep 13, 2016 1:38 pm

Re: InvokeAction returning custom objects

Post by phaneendra » Wed Oct 05, 2016 11:27 am

It's usually the way how you suggested.

But, in this case it is an Inter-process communication.

Ranorex tries to access an object from different process (WPF application).

If I do this way, it gives a casting exception.
The object returned by InvokeAction() is a proxy object.

My original question is, how can I get the real object from this proxy object.

Please find the attached error for your reference

Br,
Phanee.
Attachments
error.png
Cast error
error.png (24.81 KiB) Viewed 420 times