views:

31

answers:

2

I have a very simple ASP.NET web application created under Visual Studio 2008 (SP1), targeting .NET 3.5.

  • Startup page is a dumbed down ASPX page with 4 text boxes, a button, and two JScript functions:
    • An OnLoad handler for the body. This function just sets the values of the text boxes to certain dates and times for testing.
    • An OnClick handler for the button. This handler invokes the Localization web service and displays the results thereof.
  • Localization is a web service. Its job is to get the user's region and country information, create a CultureInfo object, and parse the date and time information so that it can verify that the start date is prior to the end date. It's the only reliable way to do this without reams of JScript code that essentially reinvents the wheel. The result is returned as a JSON string.

Everything seemed to be working just fine, until I started getting these weird error messages from the debugger. The debugger will break on this line :

        try {
            _this._webRequest.completed(Sys.EventArgs.Empty);
        }
        finally { // <-- RIGHT HERE, specifically, on the brace
            if (_this._xmlHttpRequest != null) {
                _this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
                _this._xmlHttpRequest = null;
            }
        }

The error message is this:

Microsoft JScript compilation error: Expected ';'

Now, this is baffling, and research has usually recommended ensuring that Java was installed. I scoffed at first, thinking that I, with my vast and clearly superior intellect, could not possibly have made so foolish a mistake and that everyone knew the difference between Java and JavaScript. So, when no one was looking, I tried it. It made no difference.

I have no idea what is causing this to occur. The stack trace reveals that it's the only call on the stack. There aren't even any local variables to work with. And the file that it occurs in is a generated dynamic script resource. The function, however, is the _onReadyStateChange function of the Sys.Net.XMLHttpExecutor object. So I can at least say it's occurring consistently in the AJAX code.

Has anyone else seen this? If you did, what was its cause and how did you resolve it?

Server Side:

  • Windows 2000
  • IIS 7
  • ASP.NET
  • .NET 3.5

Development

  • Visual Studio 2008 SP1
  • .NET 3.5
  • IE 8
  • IIS 7
A: 

I'm going to post the answer to this question, at the risk of embarrassing myself.

In the JScript code, I was evaluating the result of the call as follows:

function(r)
{
    var result = eval(r);
    if (!result.Succeeded)
        alert(result.Reason);
});

The problem, apparently, is that you have to enclose the JSON string in parentheses when you are passing it to eval, like this:

function(r)
{
    var result = eval("(" + r + ")");
    if (!result.Succeeded)
        alert(result.Reason);
});

Don't ask me why this works, it just does. I'll puzzle out the why-fors later.

Mike Hofer
+1  A: 

See this question for an explanation of why the parentheses are needed (and why you shouldn't use eval for parsing Json)

Jonas H