So I was getting this error when calling a page method from jquery. Google turned up quite a few variations but not the exact string, and the suggestions associated with those variations were not relevant. It turned out that in my case the data packet I was sending in the jquery ajax call was wrong. I had code like this:
MyParam = [];
...
$.ajax({
type: 'POST',
url: document.location.pathname + '/DoSomething',
data: JSON.stringify(MyParam),
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function (a, b, c, d) { console.log(a, b, c, d); }
});
and my page method looked like this:
[WebMethod()]
public static void DoSomething(List<s> B)
{
B.ToString();
}
fairly simple but there are 2 things wrong with this. The first problem was the data - I hadn't named the paramater
so the fixed javascript code looks like this:
MyParam = [];
...
$.ajax({
type: 'POST',
url: document.location.pathname + '/DoSomething',
data: JSON.stringify({B:MyParam}),
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function (a, b, c, d) { console.log(a, b, c, d); }
});
The second problem was it turns out the .NET javascript seraliser doesn't like List<t> so a quick change to the C# fixed that.
[WebMethod()]
public static void DoSomething(S[] B)
{
B.ToString();
}
So in summary - make sure you pass an object with named parameters as the data argument - not simple the content of the only parameter!