Ask a Question

Read array of strings from dotNet (CLR Bridge)

SOLVED
bwehking
Occasional Contributor

Read array of strings from dotNet (CLR Bridge)

Hello,

 

I guess I miss something obvious:

 

I'm using TestComplete 12.31.1833.7. I use the CLR Bridge to call a .NET method which returns an array of strings.

The documentation says that "single-dimensional .NET arrays" have an OleValue property, which allows to access the array members. But how do I access the members? The debugger only gives me "undefined" values. To better diagnose the issue, I even hardcoded the members of the string array on the .NET side.

 

Do you have any ideas?

Thanks in advance!

 

Bernd

 

string array.png

2 ACCEPTED SOLUTIONS

Accepted Solutions
HKosova
Moderator

Re: Read array of strings from dotNet (CLR Bridge)

Hi Bernd,

 

Try the Array.Get method:

functions.Get(0)

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

bwehking
Occasional Contributor

Re: Read array of strings from dotNet (CLR Bridge)

Hello,

 

thank you for pointing me in the right direction! But that means, that the documentation is wrong:

Single-dimensional arrays have to be accessed without using OleValue and the array elements need to be addressed using Get(), as it is stated for multi-dimensional arrays.

 

This worked:

var justTrying = Config.myConfig.get_ArrayForTestComplete();
var first = justTrying.Get(0);

I guess, the documentation should be reviewed.

 

Thank you!

 

Bernd

 

View solution in original post

3 REPLIES 3
HKosova
Moderator

Re: Read array of strings from dotNet (CLR Bridge)

Hi Bernd,

 

Try the Array.Get method:

functions.Get(0)

Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

bwehking
Occasional Contributor

Re: Read array of strings from dotNet (CLR Bridge)

Hello,

 

thank you for pointing me in the right direction! But that means, that the documentation is wrong:

Single-dimensional arrays have to be accessed without using OleValue and the array elements need to be addressed using Get(), as it is stated for multi-dimensional arrays.

 

This worked:

var justTrying = Config.myConfig.get_ArrayForTestComplete();
var first = justTrying.Get(0);

I guess, the documentation should be reviewed.

 

Thank you!

 

Bernd

 

View solution in original post

HKosova
Moderator

Re: Read array of strings from dotNet (CLR Bridge)

Hi Bernd,

 

A quick update: The behavior on your screenshot seems to be specific to JScript. JScript's native array format differs from the array format used by other scripting languages and returned by OleValue. Because of this, the OleValue array needs to be converted to the JScript array format using .toArray():

var justTrying = Config.myConfig.get_ArrayForTestComplete()
justTrying = justTrying.OleValue.toArray();
// Now you can see the "justTrying" array items in the Locals panel
// and access the array items using []
var first = justTrying[0];

We'll update the docs to better explain .NET array usage.

 

Thanks for your feedback!


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: