Development

ASP.NET WebForms ScriptResource error

You know those days when you wonder how you stay sane in this line of work?!  I’ve just come across a little gotcha that I’ve just spent almost an hour trying to nut out, so thought I’d share a potential time saver with others!

It’s one of those red-herring cases.  You get an error and it turns out to be quite unrelated to the underlying issue.  In this case it’s the following beauty which surfaced for me when a submit button was clicked on a form:

This is the error showing up in the Chrome Developer Tools, and the file it occurs in is ScriptResource.axd.

As far as the end user is concerned, nothing has happened, and the browser doesn’t appear to have responded to their click.  What is actually happening here behind the scenes is that the server is throwing a 500 error, and this is not being handled well by the Microsoft AJAX library that is performing the ajax call to submit the form.

One way to find the underlying cause of error is to check the Event Viewer on the web server (if you have this access), to find the error/warning being raised.

If you don’t have this access, though (or if you forget about the Event Viewer in the first instance, like I did!), the way I dug in to find the actual error was by temporarily turning off partial rendering, by setting EnablePartialRendering to false on my ScriptManager:

[csharp]<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="false" runat="server"></asp:ScriptManager>[/csharp]

I was then able to view the details of the actual error message (I have CustomErrors turned on for RemoteOnly, so I reproduced it locally on the server), and saw the issue was a null value being passed to a database table that wasn’t expecting null (oops!) in the button processing code.  So I fixed the issue and hey presto, issue resolved!

I hope this helps someone, there tends to be a lot of issues of this nature raised out there on Stack Overflow, MSDN etc but because this error is actually just reflecting the fact that a 500 error was thrown on the server during an AJAX call, you can get bogged down very quickly in completely unrelated causes and solutions.

You may also like
Screenshot 2016-05-22 11.21.15-step1
Getting going with Bash on Windows
Serilog in Seq
Structured Logging with Serilog in ASP.NET Core
Screenshot 2016-06-19 18.00.30
Getting Ghost Running on Bash on Windows