I am trying to convert OpenSpan.ExpressTranslators.TranslatorObject type into OpenSpan.Adapters.Controls.Button type. But at runtime it showing exception as unable to convert. There is no exception at type casting syntax. Bot throwing exception at runtime.
Exception Type: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
Message: "Cannot convert type 'OpenSpan.ExpressTranslators.TranslatorObject' to 'OpenSpan.Adapters.Controls.Button'"
Please let me if any one having some suggestions on this.
Are you able to attach a screenshot of your automation and your RuntimeLog?. This would help see what you are doing. Those two objects don't seem to be related, so it is unlikely you'd be able to cast one to another. Are you doing that in a script? If so please post that code as well.
I am trying this in type extension (Script) for a windows application control (Drawn Panel). I am trying to fetch the list of all child components using Native control object and I want child object (OpenSpan.ExpressTranslators.TranslatorObject) to be converted as "OpenSpan.Adapters.Controls.Button" type. So that I can invoke methods/properties (to implement inside script/type extension it self) which are generally available. Please find the code snippet from attachment.
Unless someone has written this exact script, the details about how to work with the DLLs are not really published anywhere. I would need to get hands-on with your solution to really offer a suggestion since this is not documented anywhere (as you would typically just perform these steps in an automation), although I do understand why you want this in a script. Perhaps I can see something in the exception that might help. Can you attach a verbose RuntimeLog?
Application I am trying automate have more than 300 text boxes where I need to collect the data and use it for comparison. And those text box doesn't have any of unique parameter to match except id which is dynamic from session to session. So I preferred to interrogate till the parent of those controls (which is a drawn panel). Created a type extension for drawn panel and written a method which will return child item values based on index (I have count of controls from drawn panel).
Limitation for this approach is that I can call only methods which are coming in native control explorer. So now I am trying to convert the generated child object into the type of normal interrogated object which will enable further exposes of methods available generally from object explorer.
I am unable to attache the runtime log due to client policy. Thanks for you reply.
That makes sense from a use case perspective, however without access to the application, I can only state that exception indicates that the object you are trying to cast from is not actually the object type you are casting to (i.e. you could not cast a boat into an elephant). Have you conformed that the button is actually of type OpenSpan.Adapters.Controls.Button? You might interrogate an instance of the button just to check its type to be certain.