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
InvokeAction returning custom objects
Re: InvokeAction returning custom objects
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. 
To get your original object type back you need to cast the returned value like this:

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...
-
- Posts: 7
- Joined: Tue Sep 13, 2016 1:38 pm
Re: InvokeAction returning custom objects
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.
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
-
- Cast error
- error.png (24.81 KiB) Viewed 551 times