views:

597

answers:

1

I'm working on a Silverlight application where I want to take advantage of the Microsoft ASP.NET AJAX Client library. I'm calling the library using the HTML Bridge that is part of Silverlight 2. Silverlight got great support for passing types between JavaScript and Managed Code, but now I've bumped against a problem.

Microsoft ASP.NET AJAX Client Libraries includes a "type system", and one of the things the framework does is validating that the parameters is of correct type. The specific function I'm calling is the Sys.Application.addHistoryPoint, and the validation code looks like this:

var e = Function.validateParams(arguments, [
    {name: "state", type: Object},
    {name: "title", type: String, mayBeNull: true, optional: true}
]);

I've tried passing all kinds of CLR types as the state parameter (C# structs, [ScriptableTypes], Dictionary types etc. And every time I get the error: "Sys.ArgumentTypeException: Object of type 'Function' cannot be converted to type 'Object'.

This error is obviously coming from the parameter validation... But WHY does ASP.NET AJAX think my types are Functions? Does anyone understand the type validation in MS AJAX?

I know I can do workarounds like calling HtmlPage.Window.Eval("...") and pass my JS integration as strings, but I don't want to do that. I want to pass a real .NET type as the state parameter.

+1  A: 

I found a pretty good overview of this here, but even that overview seemed to cover every scenario except the one you mention. I'm wondering if this can't be done because javascript objects really are functions (more or less).

What if you wrote a wrapper function that could create the state object using a string?

Bryant