EDIT: I've found an answer (with help from Tejs); see below.
I'm developing a Metro app using HTML/Javascript, along with some C#-based helper libraries. Generally speaking I'm having a lot of success calling C# methods from Javascript, but I can't seem to get passing arrays (in my specific case, arrays of strings) to work. Passing individual strings works without issue.
My code is something like this:
// in javascript project
var string1 = ...;
var string2 = ...;
var string3 = ...;
var result = MyLibrary.MyNamespace.MyClass.foo([string1, string2, string3]);
Then, in C#:
// in C# project
public sealed class MyClass {
public static string Foo(string[] strings) {
// do stuff...
}
}
The problem is that the method "Foo" gets an array with the correct length (so in the above example, 3), but all of the elements are empty. I also tried this:
public static string Foo(object[] strings) {
...
That didn't work either - again, the array was the correct size, but all the elements were null.
I've tried passing string literals, string variables, using "new Array(...)" in javascript, changing the signature of "Foo" to "params string[]" and "params object[]", all to no avail.
Since passing individual strings works fine, I can probably work around this with some hackery...but it really seems like this should work. It seems really odd to me that the array is passed in as the right size (i.e. whatever's doing the marshaling knows SOMETHING about the javascript array structure) and yet the contents aren't getting populated.
string1,string2, andstring3?new String("Hello World")for an array item? Perhaps the WinRT can't assume the object is a stringnew Array()IEnumerable<object>, what does the runtime inject for the concrete type?