Note that there are some explanatory texts on larger screens.

plurals
  1. POPass array from javascript to C# in Metro app
    primarykey
    data
    text
    <p>EDIT: I've found an answer (with help from Tejs); see below.</p> <hr> <p>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.</p> <p>My code is something like this:</p> <pre><code>// in javascript project var string1 = ...; var string2 = ...; var string3 = ...; var result = MyLibrary.MyNamespace.MyClass.foo([string1, string2, string3]); </code></pre> <p>Then, in C#:</p> <pre><code>// in C# project public sealed class MyClass { public static string Foo(string[] strings) { // do stuff... } } </code></pre> <p>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:</p> <pre><code>public static string Foo(object[] strings) { ... </code></pre> <p>That didn't work either - again, the array was the correct size, but all the elements were null.</p> <p>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.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload