My C# code is like this
- protected void Application_Error(object sender, EventArgs e)
- {
- var ex = Server.GetLastError();
- Log.Error(ex);
- var httpStatusCode = (ex is HttpException) ? (ex as HttpException).GetHttpCode() : 500;
- var httpContext = ((MvcApplication)sender).Context;
- httpContext.ClearError();
- httpContext.Response.Clear();
- httpContext.Response.StatusCode = httpStatusCode;
- var shouldHandleException = true;
- Exception exceptionToReplace;
- }
And Log.Error(ex); throws this
System.NullReferenceException: Object reference not set to an instance of an object
error cause var ex = Server.GetLastError(); is null .
My question is how to solve this error?Any info will be helpful regarding this