Error 'length' is null or not an object
I have 开发者_运维知识库a ASP.NET web application that uses ASP.NET AJAX. The application gives me following random javascript error
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; WOW64; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; MS-RTC LM 8; CIBA; .NET4.0C; .NET4.0E)
Timestamp: Fri, 2 Jul 2010 17:19:22 UTC
Message: 'length' is null or not an object
Line: 5
Char: 18997
Code: 0
URI: http://172.16.199.109/TWQAUDTUK_App/ScriptResource.axd?d=BssYA8UXb_xixM2kbWCVNiQB3yadiDxpyviVKlvm-OzfLO5PAqndPHn02Na1YNGeyuN9FBDbUO716zVqct-04yJjJTi77-kEQQ_jKSRCUY81&t=5dc69638
The place I got error is in MicrosoftAjax.js
Array.indexOf = function Array$indexOf(array, item, start) {
/// <param name="array" type="Array" elementMayBeNull="true"></param>
/// <param name="item" optional="true" mayBeNull="true"></param>
/// <param name="start" optional="true" mayBeNull="true"></param>
/// <returns type="Number"></returns>
var e = Function._validateParams(arguments, [
{name: "array", type: Array, elementMayBeNull: true},
{name: "item", mayBeNull: true, optional: true},
{name: "start", mayBeNull: true, optional: true}
]);
if (e) throw e;
if (typeof(item) === "undefined") return -1;
var length = array.length;
if (length !== 0) {
start = start - 0;
if (isNaN(start)) {
start = 0;
}
else {
if (isFinite(start)) {
start = start - (start % 1);
}
if (start < 0) {
start = Math.max(0, length + start);
}
}
for (var i = start; i < length; i++) {
if ((typeof(array[i]) !== "undefined") && (array[i] === item)) {
return i;
}
}
}
return -1;
}
How do I troubleshoot this problem?
Your array argument must be null
Perhaps the function is being called with "array" being null. You aren't checking if "array" is null before this line:
var length = array.length;
[Edit: on second thought, I think this is wrong; I think you'd get an error about "array" itself, not "length".]
It could also be that "array" is not really an array, so there's no "length" attribute on whatever was passed as "array".
Thanks for the quick response. Let me provide more information here. MicrosoftAjax.js is a part of Microsoft ASP.NET AJAX framework. I knew there is something wrong with the array parameter, but the AJAX process is all generated by ASP.NET AJAX framework. I don't know how to use the point of failure to trace into my code to find the problem. On the other hand, the problem is very RANDOM, I only got it once a while.
精彩评论