internal ConfigErrorFormatter(System.Configuration.ConfigurationException e) : base(e.Filename, null, e.Line) { _e = e; PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_PRE_PROCESSING); PerfCounters.IncrementCounter(AppPerfCounter.ERRORS_TOTAL); _message = e.BareMessage; }
/// <summary> /// Used in the rare event that the configuration file for the application is corrupted /// </summary> /// <param name="ce"></param> private static void HandleConfigurationException(System.Configuration.ConfigurationException ce) { try { // perhaps this should be checked for if it is null var in3 = ce.InnerException.InnerException; // saves having to have a reference to System.Xml just to check that we have an XmlException if (in3.GetType().Name.Equals("XmlException")) { var localSettingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "GitExtensions"); //assume that if we are having this error and the installation is not a portable one then the folder will exist. if (Directory.Exists(localSettingsPath)) { string messageContent = String.Format("There is a problem with the user.xml configuration file.{0}{0}The error message was: {1}{0}{0}The configuration file is usually found in: {2}{0}{0}Problems with configuration can usually be solved by deleting the configuration file. Would you like to delete the file?", Environment.NewLine, in3.Message, localSettingsPath); if (DialogResult.Yes.Equals(MessageBox.Show(messageContent, "Configuration Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2))) { try { Directory.Delete(localSettingsPath, true); //deletes all application settings not just for this instance - but should work //Restart GitExtensions with the same arguments after old config is deleted? if (DialogResult.OK.Equals(MessageBox.Show(String.Format("Files have been deleted.{0}{0}Would you like to attempt to restart GitExtensions?", Environment.NewLine), "Configuration Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Information))) { var args = Environment.GetCommandLineArgs(); System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = args[0]; if (args.Length > 1) { args[0] = ""; p.StartInfo.Arguments = String.Join(" ", args); } p.Start(); } } catch (IOException) { MessageBox.Show(String.Format("Could not delete all files and folders in {0}!", localSettingsPath), "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } //assuming that there is no localSettingsPath directory in existence we probably have a portable installation. else { string messageContent = String.Format("There is a problem with the application settings XML configuration file.{0}{0}The error message was: {1}{0}{0}Problems with configuration can usually be solved by deleting the configuration file.", Environment.NewLine, in3.Message); MessageBox.Show(messageContent, "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } finally // if we fail in this somehow at least this message might get somewhere { System.Console.WriteLine("Configuration Error"); System.Environment.Exit(1); } }
/// <summary> /// /// </summary> /// <param name="configurationErrorsException"></param> /// <returns>ServiceError <see cref="ServiceError"/></returns> private static ServiceError ProcessConfigurationException(System.Configuration.ConfigurationException configurationErrorsException) { ServiceError wServiceError = new ServiceError(); StringBuilder wMessage = new StringBuilder(); wMessage.AppendLine("Ocurrio un problema al intentar obtener la confuguracion del cliente al conectarce al Servicio Web. "); wMessage.AppendLine("Verifique si esta bien formado el archivo de configuracion AppConfig y si contiene la seccion que configura el Wrapper"); wMessage.AppendLine(); wMessage.AppendLine("Mensaje Web: "); wMessage.AppendLine(configurationErrorsException.Message); wServiceError.StackTrace = configurationErrorsException.StackTrace; wServiceError.Message = wMessage.ToString(); if (configurationErrorsException.InnerException != null) { wServiceError.InnerMessageException = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(configurationErrorsException.InnerException); } wMessage = null; return(wServiceError); }