Search code examples
c#asp.net-mvcasp.net-mvc-4global-asaxapplication-error

MVC - Input string was not in a correct format - Application_Error - Global.asax


I do not know where this exception is being thrown. I intercept the exception in Application_Error. Application_Error is called after the page is fully loaded. It occurs on any page.

Code of Application_Error:

protected void Application_Error(object sender, EventArgs e)
{
                string errorMessage = "";
                LogServices logServ = new LogServices();

                Exception exception = Server.GetLastError();
                string exMsg = exception.Message;
                Exception _ex = exception.InnerException;
                while(null != _ex)
                {
                    exMsg = string.Format("{0} {1}", exMsg, _ex.Message);
                    _ex = _ex.InnerException;
                }



                string logId = logServ.log(exception, "", Context.Request.UserAgent);

                if (exMsg.IndexOf("was not found") != -1)
                {
                    errorMessage = ElizeuSites.AssimEstaEscrito.Resources.Global.PageNotFound;
                    Server.ClearError();
                    string urlRedirect = String.Format("/FrontEnd/{0}/{1}?{2}={3}&errorMessage={4}", "Error", "PopUpError", "logId", logId, errorMessage);
                    Server.TransferRequest(urlRedirect);
                }
}

Captured with error Server.GetLastError():

"Input string was not in a correct format "

Stack Trace:

 em System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   em System.String.Format(IFormatProvider provider, String format, Object[] args)
   em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectorIfUnique(List`1 elements, String selectorFormatString)
   em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectorsFromIds(List`1 elements, String selectorFormatString)
   em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectorsInternal(IEnumerable`1 elements, String selectorFormatString, Func`2 isUniqueTagName, Boolean indexAsLastResort)
   em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.GenerateSelectors(IEnumerable`1 elements)
   em Microsoft.VisualStudio.Web.PageInspector.Runtime.MappingData.MappingDataUtilities.ProcessDataIntoJsonObjects(IEnumerable`1 renderedOutputList)
   em Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
   em System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   em System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Solution

  • With the tip of Hakunamatata I saw that the problem was browserlink. In the MSDN blog(Link of blog) It has the full explanation of the browserlink. I could solve the problem with the configuration below.

      <appSettings>
        <add key="vs:EnableBrowserLink" value="false"/>
      </appSettings>