在这Ajax风靡日子里,忍不住试用了一下新版的AjaxPro (AssemblyVersion: 6.2.16.1),谁知一测没点反应,Server端代码如下:
[AjaxPro.AjaxMethod]
public object[] GetNumbers(int[] a, double[] b)

{
object[] x = new object[2];
x[0] = 0;
x[1] = 0.0d;
foreach(int i in a) x[0] = (int)x[0] + i;
foreach(double i in b) x[1] = (double)x[1] + i;

}
脚本中AjaxTest.MyControl.GetNumbers([1,2,3],[1.1,2.2,3.3]).value调用异常
郁闷之余,发现AjaxPro.JavaScriptDeserializer.cs的internal static object DeserializeInternal(IJavaScriptObject o, Type type)方法出了问题
internal static object DeserializeInternal(IJavaScriptObject o, Type type)

{

//..
if(o == null)

{
return null;
}
//

else if(typeof(IJavaScriptObject).IsAssignableFrom(type))

{
return o;
}

//

if (o is JavaScriptArray && (type.IsArray || type == typeof(System.Array)))

{
return JavaScriptDeserializer.DeserializeArray((JavaScriptArray)o, type);
}

//..

}
因为满足
typeof(IJavaScriptObject).IsAssignableFrom(type),根本就没有执行到if (o is JavaScriptArray && (type.IsArray || type == typeof(System.Array))
解决方法:改为:
internal static object DeserializeInternal(IJavaScriptObject o, Type type)

{

//...
if(o == null)

{
return null;
}
//...
//added
else if ((type.IsArray || type == typeof(System.Array)) && o is JavaScriptArray)

{
return JavaScriptDeserializer.DeserializeArray((JavaScriptArray)o, type);
}
//end
else if(typeof(IJavaScriptObject).IsAssignableFrom(type))

{
return o;
}

//...

//removed
// if (o is JavaScriptArray && (type.IsArray || type == typeof(System.Array)))
// {
// return JavaScriptDeserializer.DeserializeArray((JavaScriptArray)o, type);
// }
//end

//..

}
就好了