mathare
13 years agoContributor
InvalidCastException accessing Text property
I have set up an alias for an Infragistics UltraTree in my TC project and am trying to access various properties of the tree in my script. I can cast the Name property to a string fine but when I try the same with the Text property I can an invalid cast exception and can't understand why. Can anyone help? Code snippet below:
I had a thought while writing this post - is it to do with the properties TC supports for UltraTree controls? Those listed here: http://support.smartbear.com/viewarticle/29033/
If I use a var data type rather than casting to a string I don't get the exception. Are there any downsides to just using a var type in this case? Is there any way I could safely cast to a string?
var dataTree = Connect.Aliases["InputDataTree"];
Connect.Log["Message"]((string)dataTree["Name"]());
Connect.Log["Message"]((string)dataTree["Text"]());
The exception details are:
"Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface."
I had a thought while writing this post - is it to do with the properties TC supports for UltraTree controls? Those listed here: http://support.smartbear.com/viewarticle/29033/
If I use a var data type rather than casting to a string I don't get the exception. Are there any downsides to just using a var type in this case? Is there any way I could safely cast to a string?