Reputation: 52932
This is an unusual problem that is plaguing my live server at the moment.
This is a cut down version of the code, but the Exception exception...
line is the first line in the method so nothing else is breaking before then:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
SendAnEmail(exception);
}
Every email that we receive the exception is:
Message c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\096fbf1b\bbc483be\App_Web_error.aspx.639c3968.fnow3jpv.0.cs(188): error CS0246: The type or namespace name 'Dynamic' could not be found (are you missing a using directive or an assembly reference?)
I was baffled for a while and in the end decided to set customErrors
to Off
so I could view the exception, thinking it would simply be the above exception again. However the one displayed on the website is the actual error, which in the above case was index out of range due to some code accessing an erroneously empty array.
So in my mind, the exception is generated, and it jumps to the global error handler which gets the last error, but the last error is always the one above, every time.
Any ideas? I don't know if the actual type of error (complaining about dynamic) is relevant or not. I've googled it to death and the only thing I can find is having your app pool set incorrectly - but the entire site is .net 4 and we use some .net 4.5 code etc. without any issues. I've also tried deleting the temporary files as per some other instructions but no luck.
Do any suggestions spring to mind?
The application is an MVC 3 website.
Upvotes: 1
Views: 810
Reputation: 392
Looks like your website throws an exception, tries to redirect you on customErrors page and another exception happens during the compilation of error page - that's what you get in Application_Error. That explains why when custom errors are turned off, you get your expected exception. In your case, I would prefer to implement a child attribute derived from HandleErrorAttribute, apply it to your controllers/base controller and send emails there, not in Application_Error method.
Here is a nice article about HandleErrorAttribute usage.
Upvotes: 1