tags:

views:

32

answers:

3

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?

+1  A: 

Your array argument must be null

Gregoire
+1  A: 

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".

Richard Walters
A: 

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.

hehongyu2000
You can, and indeed should, edit your question to provide this extra information rather than posting it as an answer.
ChrisF
sorry, I am not very familiar with Stack Overflow. In other discussion group, I usually just post something right after other people's post to provide more information, so they will know it's a piece of new information. If I edit my original question, how to let them know it's additional information? Thanks.
hehongyu2000

related questions