Daniel Magliola
Daniel Magliola

Reputation: 32392

'Invalid Argument' Error in IE, in a line number that doesn't exist

I'm getting the following error in IE 6:

Line: 454  
Char: 13  
Error: Invalid Argument  
Code: 0  
URL: xxxxx/Iframe1.aspx 

and I can't for the life of me find what's causing this.

This only happens in a situation where I have a main page that has several IFrames, and it only happens when I have one particular IFrame (the one pointed to by the URL in the error message), and that IFrame is invisible at the time of loading.
I've narrowed it up to there, but I still can't find anything more specific...

The IFrame in question doesn't have 454 lines in its HTML, nor do any of the JS files referred by it.

I tried attaching VS to iexplore.exe as a debugger, and it breaks when the error occurs, but then tells me "There is no source code available for the current location"...

Any suggestions on how I can go about chasing this one?


UPDATE: I found this problem through brute-force, basically, commenting everything out and uncommenting randomly...
But the question still stands: what is the rational way to find where the error is, when IE reports the wrong line number / file?

Upvotes: 9

Views: 46544

Answers (8)

neave
neave

Reputation: 2531

A note to other readers: I recently had this "Invalid argument." error reported in IE7-9 and eventually found that it was down to the way I was using setTimeout/setInterval.

This is wrong, in IE:

var Thing = {};
Thing.myFunc = function() { ... };
setTimeout(Thing.myFunc, 1000);

Instead, wrap the callback in an anonymous function like so:

var Thing = {};
Thing.myFunc = function() { ... };
setTimeout(function() { Thing.myFunc(); }, 1000);

and no more "invalid argument" errors.

Upvotes: 1

Dawn Green
Dawn Green

Reputation: 493

Like NickFitz pointed out, styling was an issue with my code.

document.getElementById('sums<%= event.id %>').style.border='1px solid #3b3b3b;'

I removed the border style and my IE issues were gone.

Upvotes: 0

Andy
Andy

Reputation: 3171

IE9 has a browser mode.

Open up Developer Tools, then select the version you want to emulate in the console, reload the page with errors, and the console will show you line numbers and the correct file where the error is.

Upvotes: 2

Vid
Vid

Reputation: 1

Another possibility:

I do a lot of dev between two computers, at home and at work, so I often email myself or download pages from the server to work on. Recently I realised that Vista has a habit of unilaterally applying blocks to certain files when they are downloaded in certain ways, without notifying me that it is doing this.

The result is that, for example, an HTML page wants to access the .js file in its header, but it doesn't have permission to access local files. In this case, it doesn't matter what you write in the .js file, the browser will never even read it, and an irksome Line: 0 error will result.

So before you comb your code for an error, check your HTML page's properties, and see if it hasn't been blocked by the OS....

Upvotes: 0

Bryan Migliorisi
Bryan Migliorisi

Reputation: 9210

Try using the Microsoft Script Debugger or DebugBar (http://www.debugbar.com) which may give you some better IE6 debugging tools. They always help me with IE6.

Also, does this happen in any newer versions of IE or just in IE6?

Upvotes: 6

tessa
tessa

Reputation: 828

I run into this problem a lot too, and I've also resorted to commenting everything out until I find the problem. One thing that I find to be useful is to add a try/catch block to every javascript method. Sometimes I add an alert to tell what method the error came from. Still tedious, but easier than trial and error commenting. And if you add them every time you write a new method it saves a lot of time in the event errors like those occur.

function TestMethod()
{
    try
    {
        //whatever
    }
    catch (ex)
    {
        ShowError(ex.description);
        //alert("TestMethod");
    }
}

Upvotes: 1

Vilx-
Vilx-

Reputation: 106920

IE's Javascript engine is disgusting when it comes to debugging. You can try enabling script debugging in the Advanced Options, and then if you have Visual Studio installed it will jump to the place of error... if you're lucky. Other times you don't get anything, especially if the code was eval()'ed.

Another thing about these line numbers is that it doesn't reflect which file the error is happening in. I've had cases where the line number was actually correct, but it was in a linked .js file, not the main file.

Upvotes: 11

NickFitz
NickFitz

Reputation: 35051

It's virtually impossible to debug this without a live example, but one thing that often causes an "Invalid Argument" error in Internet Explorer is trying to set an incorrect value for a style property.

So something like:

document.getElementById("foo").style.borderWidth = bar + "px";

when "bar" has the value null, or undefined, or is the string "grandma", will cause it, as "grandmapx" isn't a valid value for the borderWidth style property.

Upvotes: 5

Related Questions