This project has moved. For the latest updates, please go here.

Parameter number conflict.

Aug 5, 2014 at 7:05 AM
my code:
engine.AddHostObject("$", new Action<dynamic>(o => new Window(f).AddEventHandler("Load", o)));
            engine.AddHostObject("$", new Action<string, dynamic>((n, o) => new Window(f).AddEventHandler(n, o)));
Coordinator
Aug 5, 2014 at 3:30 PM
Hi furesoft,

Can you give us more info? Are you seeing a compilation error? Runtime exception? Is there a stack, line number, etc.?

Thanks!
Aug 5, 2014 at 4:51 PM
my js:
$(function(sender, e) {
            alert("hello to my EFML-Application :D");
        });
        $("FormClosing", function(sender, e) {
            alert("Application is closing");
        });
no line number, no compilation error. COMException is throwed
Coordinator
Aug 5, 2014 at 5:53 PM
Hi furesoft,

JavaScript doesn't support property overloading. Your host code sets script property "$" to a delegate that takes one argument, then overwrites it with a delegate that takes two arguments. Then your script code invokes the property and passes a single argument, and that fails because two are required.

Cheers!
Aug 5, 2014 at 6:00 PM
i dont understand what you mean, give me a code example, please
Coordinator
Aug 5, 2014 at 6:24 PM
  1. Your first call to AddHostObject() creates a property named "$" whose value is a delegate with one parameter.
  2. Your second call to AddHostObject() overwrites the property created in step 1. The new value is a delegate with two parameters.
  3. The first line of your script invokes the delegate assigned in step 2, but passes only one argument.
Aug 5, 2014 at 6:34 PM
when i change the order of addhostobject i get this exception: One can not be called non-delegate type.
Coordinator
Aug 5, 2014 at 7:44 PM
That makes sense. With the order reversed, the "$" property ends up being set to a one-parameter delegate. The second call in your script invokes it with two arguments, which is OK, but the first argument is a string that's assumed to be a script function. When the event is raised, an attempt is made to invoke the string, which understandably fails.

The bottom line is that a JavaScript property can't have two values. However, you can create a single delegate that supports both calling patterns:
public delegate void DollarSignFunc(object arg1, object arg2 = null);
...
engine.AddHostObject("$", new DollarSignFunc((arg1, arg2) => {
    var name = arg1 as string;
    if (name == null)
        new Window(f).AddEventHandler("Load", arg1);
    else
        new Window(f).AddEventHandler(name, arg2);
}));
Good luck!
Aug 6, 2014 at 9:33 AM
how can i use a third version?

$("elementname")
Coordinator
Aug 6, 2014 at 1:40 PM
Perhaps something like this:
engine.AddHostObject("$", new DollarSignFunc((arg1, arg2) => {
    var name = arg1 as string;
    if (name == null)
        new Window(f).AddEventHandler("Load", arg1);
    else if (arg2 != null)
        new Window(f).AddEventHandler(name, arg2);
    else {
        // add code here
    }
}));
As long as the calling pattern can be inferred from the arguments, you can support as many as you need.

Cheers!
Marked as answer by furesoft on 8/6/2014 at 6:53 AM
Aug 6, 2014 at 2:09 PM
thanks it works