1

I am porting one of our node.js Azure Functions to C#, so this is C# running in a .csx container. I'm running in the local Windows Function emulator and have also tried this in the Functions runtime in Azure, both show the same compiler errors.

I have seen multiple other questions asking something similar, but there seems to be something different about running in a .csx file or the functions runtime as none of the answers work.

This is the method signature that I'm calling :

DocumentClient.ExecuteStoredProcedureAsync<TValue> Method (Uri, Object[])

This is the working code from run.csx:

string param1 = "param1";
string param2 = "param2";

// object[] params = {"param1", "param2"};

var response = await client.ExecuteStoredProcedureAsync<object>(
  sprocUri,
  param1,
  param2
);

When I try to add the two params into an array and uncomment the line object[] params = {"param1", "param2"}; then I get this error from the compiler:

run.csx(72,14): error CS1001: Identifier expected
run.csx(72,14): error CS1003: Syntax error, ',' expected
run.csx(72,21): error CS1002: ; expected
run.csx(72,21): error CS1525: Invalid expression term '='
run.csx(72,23): error CS1525: Invalid expression term '{'
run.csx(72,23): error CS1002: ; expected
run.csx(72,32): error CS1002: ; expected
run.csx(72,32): error CS1513: } expected
run.csx(72,42): error CS1002: ; expected
Compilation failed.

(Line 72 corresponds to the array assignment statement)

I have tried all of these different ways to define the array, but I get similar errors for each:

Object[] params = {"param1", "param2"};
object[] params = new[] {"param1", "param2"};
object[] params = new[] {param1, param2};
string[] params = {"param1", "param2"};
string[] params = new string[] {"param1", "param2"};
dynamic[] params = new[] {"param1", "param2"};

Is there something different about Azure Functions where it needs a different style of array definition? There is nothing mentioned about arrays in the C# Developer Reference.

1 Answer 1

2

The issue you are facing is that you named the variable params which is a reserved word in C# (see params (C# reference)). Try using a different name.

Should you be really set on using params, you could possibly use a @ prefix which can be used in C# to create an identifier which would be a reserved word otherwise:

object[] @params = { param1, param2 };
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I changed it to args and it works perfectly now.
Out of curiosity, is there a secret to using an ArrayList instead of an object array in the method call?
@Graham no, it should be the same: var args = new ArrayList { param1, param2 }; - as long as the method takes ArrayList as an argument, of course. Speaking of ArrayList, that is a class you mostly don't see past the first version of C# and/or legacy code. It might be more idiomatic to use List<object> to express "I really don't know the type" instead of "there is some type but I cannot express it" semantics of ArrayList. But that is only if you can change the method signature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.