none
Read of appSettings in external configuration only producing defaults

    Question

  • Okay, so the scenario is that I am playing around with the configuration classes in the .Net Framework.  I understand how to create custom sections, use the user-level and applicationSettings part, but also want to understand how to use the appSettings element.  In particular because I'm piecing together a white-paper regarding the use of configuration files with a specific application and I don't want to leave any stone unturned.

    So this is my issue:  I develop a class library (*.dll) that is the required executable for application development using a specific third-party application.  This *.dll is automatically loaded into the process space by this third-party app.  So I'm testing how to use the <appSettings> element as an external config file (Auxiliary.config) to be associated with the *.dll.  I've got it to read default values just fine as well as write changes out.  One interesting thing about writing out is that it doesn't persist changes to the Auxiliary.config, but instead persists to the ThirdPartyApp.exe.config.  I don't have a problem with that if that's how it's supposed to work with the custom merge.  If I don't close out the Configuration reference after modifying, I can read the changes just fine.  However, if I create the Configuration reference separately, it only provides the default values no matter what I do.  Any help would be greatly appreciated.  Here's the code so far.  It's the section at the botton commented with //Display Modified Settings that I can't seem to get to display the modified settings.  Instead it only provides the default values left to reside in the Auxiliary.config file.  Maybe my issue is that I need to be more direct at persisting in the Auxiliary.config file?  If so, how?

     public static void MyConfig()
        {
          //Read the stored Settings
          StringBuilder sbSettings = new StringBuilder();
    
    
          
    
          try
          {
            ////Get the application configuration file
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    
            AppSettingsSection appSettings = config.AppSettings;
    
            //Associate application configuration with acad.exe.config application configuration
            //via a custom merge        
            appSettings.File = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
          }
          catch (System.Exception ex)
          {
            sbSettings.Append(string.Format("Error: [Initializing Settings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
    
          
          //Read the stored Default Settings
          try
          {
            ////Get the application configuration file
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    
            sbSettings.Append("\nInitial (Default) Settings:\n");
    
            sbSettings.Append(string.Format("\tmyString: {0}\n",
              IntConfig.Properties.Settings.Default.myString));
            sbSettings.Append(string.Format("\tmyBoolean: {0}\n",
              IntConfig.Properties.Settings.Default.myBoolean.ToString()));
            sbSettings.Append(string.Format("\tmyColor: {0}\n",
              IntConfig.Properties.Settings.Default.myColor.ToString()));
            sbSettings.Append(string.Format("\tmySize: {0}\n",
              IntConfig.Properties.Settings.Default.mySize.ToString()));
    
            //Now read the appSettings values
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "fontFilePath", ConfigurationManager.AppSettings["fontFilePath"]));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "bmpFilePath", ConfigurationManager.AppSettings["bmpFilePath"]));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "plotstylesFilePath", ConfigurationManager.AppSettings["plotstylesFilePath"]));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myInteger", ConfigurationManager.AppSettings["myInteger"]));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myColor", ConfigurationManager.AppSettings["myColor"]));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myLine3d", ConfigurationManager.AppSettings["myLine3d"]));
    
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
          catch (System.Exception ex)
          {
            sbSettings.Append(string.Format("Error: [Display Default AppSettings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
    
          //
    
          //appSettings values returned are string values... 
          //This means that the values stored are not strongly typed.
          //To convert, try using various approaches such as TryParse for many of the System.Object data types
          //or creating your own String/Object conversion as with the Line3d setting
          //Try updating appSettings
          try
          {
            ////Get the application configuration file
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            AppSettingsSection appSettings = config.AppSettings;
    
            //convert string values to specified data type
            int myInteger;
            int.TryParse(ConfigurationManager.AppSettings["myInteger"], out myInteger);
    
            Color myColor = Color.FromName(ConfigurationManager.AppSettings["myColor"]);
    
            Line3d myLine3d;
            Line3dStringConverter.TryParse(ConfigurationManager.AppSettings["myLine3d"], out myLine3d);
    
            //modify the values
            myInteger = 5000;
            myColor = Color.Blue;
            LineSegment3d NewLine3d = new LineSegment3d(new Point3d(5, 5, 5), new Point3d(10, 10, 10));
    
            //Save values
            appSettings.Settings["fontFilePath"].Value = @"C:\TestFonts";
            appSettings.Settings["bmpFilePath"].Value = @"C:\TestIcons";
            appSettings.Settings["plotstylesFilePath"].Value = @"C:\TestPlotStyles";
            appSettings.Settings["myInteger"].Value = myInteger.ToString();
            appSettings.Settings["myColor"].Value = myColor.Name;
            appSettings.Settings["myLine3d"].Value = Line3dStringConverter.ToString(NewLine3d.StartPoint, NewLine3d.EndPoint);
    
            // Save the configuration file.
            config.Save(ConfigurationSaveMode.Modified);
    
            // Force a reload of a modified section.
            ConfigurationManager.RefreshSection("appSettings");
    
          }
          catch (ConfigurationErrorsException ex)
          {
    
            sbSettings.Append(string.Format("Error: [Create/ModifyAppSettings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
          .WriteMessage(sbSettings.ToString());
          }
    
    
    
    
          //Display Modified Settings
          sbSettings.Remove(0, sbSettings.Length);
          sbSettings.Append("\nappSettings Section:\n");
          try
          {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    
            AppSettingsSection appSettings = config.AppSettings;
    
            sbSettings.Append("\nappSettings: Persisted Values in acad.exe.config\n");
    
    
            sbSettings.Append(string.Format("\tmyString: {0}\n",
              IntConfig.Properties.Settings.Default.myString));
            sbSettings.Append(string.Format("\tmyBoolean: {0}\n",
              IntConfig.Properties.Settings.Default.myBoolean.ToString()));
            sbSettings.Append(string.Format("\tmyColor: {0}\n",
              IntConfig.Properties.Settings.Default.myColor.ToString()));
            sbSettings.Append(string.Format("\tmySize: {0}\n",
              IntConfig.Properties.Settings.Default.mySize.ToString()));
    
            //Now read the appSettings values
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "fontFilePath", appSettings.Settings["fontFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "bmpFilePath", appSettings.Settings["bmpFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "plotstylesFilePath", appSettings.Settings["plotstylesFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myInteger", appSettings.Settings["myInteger"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myColor", appSettings.Settings["myColor"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myLine3d", appSettings.Settings["myLine3d"].Value));
    
          }
          catch (ConfigurationErrorsException e)
          {
            sbSettings.Append(string.Format("Error: [DisplayAppSettings: {0}]", e.ToString()));
          }
    
          ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                  .WriteMessage(sbSettings.ToString());
    
        }

     

     


    Jason
    Tuesday, August 02, 2011 4:48 PM

Answers

  • After much frustration I figured out that I have to eliminate all the ConfigurationManager.AppSettings... calls and change the Configuration reference to be based off the mapped exe configuration.  This allows the settings to be saved in the Auxiliary.config (which actually makes more sense anyways).  The only loss is that I can no longer obtain the default settings.  But that should just have to be taken into consideration.  But if anyone knows how to make it work the way I posted it above, I'd be more than happy to learn.  Sometimes you never know what you need until you need it.

    For now, here's my code sample that works:

          //Read the stored Settings
          StringBuilder sbSettings = new StringBuilder();
    
          try
          {
            ////Get the application configuration file
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    
            AppSettingsSection appSettings = config.AppSettings;
    
            //Associate application configuration with acad.exe.config application configuration
            //via a custom merge        
            //appSettings.File = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
            //config.Save(ConfigurationSaveMode.Modified);
            //ConfigurationManager.RefreshSection("appSettings");
          }
          catch (System.Exception ex)
          {
            sbSettings.Append(string.Format("Error: [Initializing Settings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
    
    
          //Read the stored Default Settings
          try
          {
            ////Get the application configuration file
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            sbSettings.Append("\nInitial Settings:\n");
    
            sbSettings.Append(string.Format("\tmyString: {0}\n",
              IntConfig.Properties.Settings.Default.myString));
            sbSettings.Append(string.Format("\tmyBoolean: {0}\n",
              IntConfig.Properties.Settings.Default.myBoolean.ToString()));
            sbSettings.Append(string.Format("\tmyColor: {0}\n",
              IntConfig.Properties.Settings.Default.myColor.ToString()));
            sbSettings.Append(string.Format("\tmySize: {0}\n",
              IntConfig.Properties.Settings.Default.mySize.ToString()));
    
            //Now read the appSettings values
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "fontFilePath", config.AppSettings.Settings["fontFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "bmpFilePath", config.AppSettings.Settings["bmpFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "plotstylesFilePath", config.AppSettings.Settings["plotstylesFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myInteger", config.AppSettings.Settings["myInteger"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myColor", config.AppSettings.Settings["myColor"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myLine3d", config.AppSettings.Settings["myLine3d"].Value));
    
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
          catch (System.Exception ex)
          {
            sbSettings.Append(string.Format("Error: [Display Default AppSettings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
    
          
    
          //appSettings values returned are string values... 
          //This means that the values stored are not strongly typed.
          //To convert, try using various approaches such as TryParse for many of the System.Object data types
          //or creating your own String/Object conversion as with the Line3d setting
          //Try updating appSettings
          try
          {
            ////Get the application configuration file
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            //convert string values to specified data type
            int myInteger;
            int.TryParse(config.AppSettings.Settings["myInteger"].Value, out myInteger);
    
            Color myColor = Color.FromName(config.AppSettings.Settings["myColor"].Value);
    
            Line3d myLine3d;
            Line3dStringConverter.TryParse(config.AppSettings.Settings["myLine3d"].Value, out myLine3d);
    
            //modify the values
            myInteger = 5000;
            myColor = Color.Blue;
            LineSegment3d NewLine3d = new LineSegment3d(new Point3d(5, 5, 5), new Point3d(10, 10, 10));
    
            //Save values
            config.AppSettings.Settings["fontFilePath"].Value = @"C:\TestFonts";
            config.AppSettings.Settings["bmpFilePath"].Value = @"C:\TestIcons";
            config.AppSettings.Settings["plotstylesFilePath"].Value = @"C:\TestPlotStyles";
            config.AppSettings.Settings["myInteger"].Value = myInteger.ToString();
            config.AppSettings.Settings["myColor"].Value = myColor.Name;
            config.AppSettings.Settings["myLine3d"].Value = Line3dStringConverter.ToString(NewLine3d.StartPoint, NewLine3d.EndPoint);
    
            // Save the configuration file.
            config.Save(ConfigurationSaveMode.Modified);
    
            // Force a reload of a modified section.
            ConfigurationManager.RefreshSection("appSettings");
    
          }
          catch (ConfigurationErrorsException ex)
          {
    
            sbSettings.Append(string.Format("Error: [Create/ModifyAppSettings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
          .WriteMessage(sbSettings.ToString());
          }
    
    
    
    
          //Display Modified Settings
          sbSettings.Remove(0, sbSettings.Length);
          sbSettings.Append("\nappSettings Section:\n");
          try
          {
    
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            AppSettingsSection appSettings = config.AppSettings;
    
            sbSettings.Append("\nappSettings: Persisted Values in acad.exe.config\n");
    
    
            sbSettings.Append(string.Format("\tmyString: {0}\n",
              IntConfig.Properties.Settings.Default.myString));
            sbSettings.Append(string.Format("\tmyBoolean: {0}\n",
              IntConfig.Properties.Settings.Default.myBoolean.ToString()));
            sbSettings.Append(string.Format("\tmyColor: {0}\n",
              IntConfig.Properties.Settings.Default.myColor.ToString()));
            sbSettings.Append(string.Format("\tmySize: {0}\n",
              IntConfig.Properties.Settings.Default.mySize.ToString()));
    
            //Now read the appSettings values
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "fontFilePath", appSettings.Settings["fontFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "bmpFilePath", appSettings.Settings["bmpFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "plotstylesFilePath", appSettings.Settings["plotstylesFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myInteger", appSettings.Settings["myInteger"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myColor", appSettings.Settings["myColor"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myLine3d", appSettings.Settings["myLine3d"].Value));
    
          }
          catch (ConfigurationErrorsException e)
          {
            sbSettings.Append(string.Format("Error: [DisplayAppSettings: {0}]", e.ToString()));
          }
    
          ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                  .WriteMessage(sbSettings.ToString());

     


    Jason
    Tuesday, August 02, 2011 6:15 PM

All replies

  • After much frustration I figured out that I have to eliminate all the ConfigurationManager.AppSettings... calls and change the Configuration reference to be based off the mapped exe configuration.  This allows the settings to be saved in the Auxiliary.config (which actually makes more sense anyways).  The only loss is that I can no longer obtain the default settings.  But that should just have to be taken into consideration.  But if anyone knows how to make it work the way I posted it above, I'd be more than happy to learn.  Sometimes you never know what you need until you need it.

    For now, here's my code sample that works:

          //Read the stored Settings
          StringBuilder sbSettings = new StringBuilder();
    
          try
          {
            ////Get the application configuration file
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            //Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    
            AppSettingsSection appSettings = config.AppSettings;
    
            //Associate application configuration with acad.exe.config application configuration
            //via a custom merge        
            //appSettings.File = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
            //config.Save(ConfigurationSaveMode.Modified);
            //ConfigurationManager.RefreshSection("appSettings");
          }
          catch (System.Exception ex)
          {
            sbSettings.Append(string.Format("Error: [Initializing Settings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
    
    
          //Read the stored Default Settings
          try
          {
            ////Get the application configuration file
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            sbSettings.Append("\nInitial Settings:\n");
    
            sbSettings.Append(string.Format("\tmyString: {0}\n",
              IntConfig.Properties.Settings.Default.myString));
            sbSettings.Append(string.Format("\tmyBoolean: {0}\n",
              IntConfig.Properties.Settings.Default.myBoolean.ToString()));
            sbSettings.Append(string.Format("\tmyColor: {0}\n",
              IntConfig.Properties.Settings.Default.myColor.ToString()));
            sbSettings.Append(string.Format("\tmySize: {0}\n",
              IntConfig.Properties.Settings.Default.mySize.ToString()));
    
            //Now read the appSettings values
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "fontFilePath", config.AppSettings.Settings["fontFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "bmpFilePath", config.AppSettings.Settings["bmpFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "plotstylesFilePath", config.AppSettings.Settings["plotstylesFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myInteger", config.AppSettings.Settings["myInteger"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myColor", config.AppSettings.Settings["myColor"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myLine3d", config.AppSettings.Settings["myLine3d"].Value));
    
            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
          catch (System.Exception ex)
          {
            sbSettings.Append(string.Format("Error: [Display Default AppSettings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                    .WriteMessage(sbSettings.ToString());
          }
    
          
    
          //appSettings values returned are string values... 
          //This means that the values stored are not strongly typed.
          //To convert, try using various approaches such as TryParse for many of the System.Object data types
          //or creating your own String/Object conversion as with the Line3d setting
          //Try updating appSettings
          try
          {
            ////Get the application configuration file
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            //convert string values to specified data type
            int myInteger;
            int.TryParse(config.AppSettings.Settings["myInteger"].Value, out myInteger);
    
            Color myColor = Color.FromName(config.AppSettings.Settings["myColor"].Value);
    
            Line3d myLine3d;
            Line3dStringConverter.TryParse(config.AppSettings.Settings["myLine3d"].Value, out myLine3d);
    
            //modify the values
            myInteger = 5000;
            myColor = Color.Blue;
            LineSegment3d NewLine3d = new LineSegment3d(new Point3d(5, 5, 5), new Point3d(10, 10, 10));
    
            //Save values
            config.AppSettings.Settings["fontFilePath"].Value = @"C:\TestFonts";
            config.AppSettings.Settings["bmpFilePath"].Value = @"C:\TestIcons";
            config.AppSettings.Settings["plotstylesFilePath"].Value = @"C:\TestPlotStyles";
            config.AppSettings.Settings["myInteger"].Value = myInteger.ToString();
            config.AppSettings.Settings["myColor"].Value = myColor.Name;
            config.AppSettings.Settings["myLine3d"].Value = Line3dStringConverter.ToString(NewLine3d.StartPoint, NewLine3d.EndPoint);
    
            // Save the configuration file.
            config.Save(ConfigurationSaveMode.Modified);
    
            // Force a reload of a modified section.
            ConfigurationManager.RefreshSection("appSettings");
    
          }
          catch (ConfigurationErrorsException ex)
          {
    
            sbSettings.Append(string.Format("Error: [Create/ModifyAppSettings: {0}]", ex.ToString()));
            ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
          .WriteMessage(sbSettings.ToString());
          }
    
    
    
    
          //Display Modified Settings
          sbSettings.Remove(0, sbSettings.Length);
          sbSettings.Append("\nappSettings Section:\n");
          try
          {
    
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = @"C:\Projects - Visual Studio 2008\_WhitePaper Study - Configuration vs INI\IntConfig\IntConfig\bin\Debug\Auxiliary.config";
    
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
            AppSettingsSection appSettings = config.AppSettings;
    
            sbSettings.Append("\nappSettings: Persisted Values in acad.exe.config\n");
    
    
            sbSettings.Append(string.Format("\tmyString: {0}\n",
              IntConfig.Properties.Settings.Default.myString));
            sbSettings.Append(string.Format("\tmyBoolean: {0}\n",
              IntConfig.Properties.Settings.Default.myBoolean.ToString()));
            sbSettings.Append(string.Format("\tmyColor: {0}\n",
              IntConfig.Properties.Settings.Default.myColor.ToString()));
            sbSettings.Append(string.Format("\tmySize: {0}\n",
              IntConfig.Properties.Settings.Default.mySize.ToString()));
    
            //Now read the appSettings values
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "fontFilePath", appSettings.Settings["fontFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "bmpFilePath", appSettings.Settings["bmpFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "plotstylesFilePath", appSettings.Settings["plotstylesFilePath"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myInteger", appSettings.Settings["myInteger"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myColor", appSettings.Settings["myColor"].Value));
            sbSettings.Append(string.Format("\n\tKey: {0} Value: {1}", "myLine3d", appSettings.Settings["myLine3d"].Value));
    
          }
          catch (ConfigurationErrorsException e)
          {
            sbSettings.Append(string.Format("Error: [DisplayAppSettings: {0}]", e.ToString()));
          }
    
          ThirdPartyApp.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
                  .WriteMessage(sbSettings.ToString());

     


    Jason
    Tuesday, August 02, 2011 6:15 PM
  • Thanks for sharing that with us, Jason.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 03, 2011 7:36 AM
    Moderator