cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Functions From .NET Assemblies - Array

Highlighted
Occasional Contributor

Calling Functions From .NET Assemblies - Array

Hi all!



I have a C# method looking like this:

public string[] Foo(int a, int b, int c)



I would like to call it in TestComplete like this:

var t = testCompleteHelper.Foo(0, 0, 0); 

Log.Message("foo: "+t[0]);  



For some reason TestComplete says the value is undefied.



string, int as return values work perfectly fine for me, but somehow string array doesnt seem to do in TestComplete. I've tried to use it via OleValue, but it did not work either: t[0].OleValue or t.OleValue[0]



I would really appreciate any help.



Best Regards,

Attila
3 REPLIES 3
Highlighted
Staff

RE: Calling Functions From .NET Assemblies - Array

Hi Attila,


Try using the following code --




var arr = testCompleteHelper.Foo(0, 0, 0); 

Log.Message("foo: " + arr.GetValue(0).OleValue);  


When you call your .NET method, TestComplete gets the array object as it is specified in .NET. To reach array items, you have to use this object's methods.


I guess, managed applications actually work with the same objects too. However, the C# compiler adds all the needed helper calls behind the scenes, so you use a simpler notation (e.g. arr[0]) in C# source code.

I’m not a member of the SmartBear Support Team, I’m just helping users in this community.
Any views or opinions expressed do not necessarily represent those of SmartBear Software.

-----
Highlighted
Occasional Contributor

Re: RE: Calling Functions From .NET Assemblies - Array

Hi,

 

I am facing a similar problem with String Array in JavaScript.

I am trying to pass a String array to a parameter but it always falis with Type Mismatch error.

 

Below is the JavaSript code that I am using.

 

dotNET.<dll>.<class1>.GetInstance.<field> = ["/INI=C:\\Temp\\Text.txt"];

 

the <field> above is expecting a DotNet String array but it is not accepting JavaScript array. is there a way to cast JS array to dotNet array.

 

 

Thanks,

Yusuf

Highlighted
Community Hero

Re: RE: Calling Functions From .NET Assemblies - Array

Hi Yusuf,

 

Try the advice by @HKosova from here: https://community.smartbear.com/t5/TestComplete-Functional-Web/Working-with-array-in-dotNET/m-p/8915...

 

> dotNET.<dll>.<class1>.GetInstance.<field> = ["/INI=C:\\Temp\\Text.txt"];

Also, I am not sure about .GetInstance() call - maybe you first must create an instance of the object by calling its constructor (one of .zctor() methods) and work with the property of the created instance.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!

Retrieve Data from a Web Page

Participate!
Top Kudoed Authors