views:

55

answers:

0

Similar to this http://stackoverflow.com/questions/45169/how-do-i-return-an-array-of-strings-from-an-activex-object-to-jscript but in C#.

I have an COM control that passes back an array of strings to javascript. It seems like javascript cant understand what it is I am passing back and the array in javascript is always undefined.

Javascript:

try
 {
  keystore.openKeyStore("MY", true, false);
  var fNames = new Array();
  fNames = keystore.getAllFriendlyNames();
  document.getElementById('par').innerHTML = fNames[0];
 }
 catch(err)
 {
  document.getElementById('err').innerHTML = err.description;
 }

That outputs 'undefined' for fNames[0];

C#:

    public object[] getAllFriendlyNames()
    {
        if (!keystoreInitialized)
            throw new Exception("Key store has not been initialized");

        X509Certificate2Collection allCerts = certificateStore.Certificates;

        int storeSize = allCerts.Count;

        if (storeSize == 0)
            throw new Exception("Empty Key Store, could have opened using the wrong keystore name.");

        object[] friendlyNames = new object[storeSize];

        for (int i = 0; i < storeSize; i++)
        {
            string friendlyName = allCerts[i].FriendlyName;

            if (friendlyName == "")
                friendlyName = allCerts[i].Subject;

            friendlyNames[i] = (object) friendlyName;
        }

        return friendlyNames;
  }

I've tried returning both object arrays and string arrays to no avail.