How to pass a VB6 string array [Assume, s =Array("a", "b", "c", "d")] to C# .Net through COM Interop?
I tried to implement passing C# string array to VB and VB string array to C# as below C#->VB working fine but other way (VB=>C#) giving a compile error called
Function or interface marked as restricted, or the function uses an automation type not supported in visual basic
My code below
C#
public interface ITest
{
string[] GetArray();
void SetArray(string[] arrayVal );
}
public class Test : ITest
{
string[] ITest.GetArray() { //Working fine
string[] stringArray = { "red ", "yellow", "blue" };
return stringArray;
}
}
void ITest.SetArray(string[] arrayVal) //Giving an issue
{
string[] stringArray1 = arrayVal;
}
VB
Dim str As Variant
Debug.Print ".NET server returned: "
For Each str In dotNETServer.GetArray 'dotNETServer=TestServer.Test
Debug.Print str
Next
Dim arr(3) As String
arr(1) = "Pahee"
arr(2) = "Tharani"
arr(3) = "Rathan"
dotNETServer.SetArray (arr) 'This one causing the compile error which I mentioned earlier
Update: ::::::
We need to pass the array as reference in C#. Change it in the interface and method
void SetArray(ref string[] arrayVal ); //ref added