Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:45:26+00:00 2026-05-11T05:45:26+00:00

I have a dll that I want to read from a manually specified app.config

  • 0

I have a dll that I want to read from a manually specified app.config file (the dll is an .net extension to a native com dll that is a Microsoft Management Console snap in, so there is no mmc.exe.config). I have been able to open the config file, read the relevant group and section to get the setting that I want. Like this:

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();             fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + '.config';              Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);             ShowSectionGroupCollectionInfo(config.SectionGroups);             ConfigurationSectionGroup group = config.SectionGroups['applicationSettings'];             ClientSettingsSection section = group.Sections['Namespace.Properties.Settings'] as ClientSettingsSection;             SettingElement sectionElement = section.Settings.Get('AllowedPlugins');              SettingValueElement elementValue = sectionElement.Value; 

The settings are a string collection and a string. like so:

<applicationSettings>     <Namespace.Properties.Settings>         <setting name='AllowedPlugins' serializeAs='Xml'>             <value>                 <ArrayOfString xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'                     xmlns:xsd='http://www.w3.org/2001/XMLSchema'>                     <string>Plugin1.Name</string>                     <string>Plugin2.Name</string>                     <string>Plugin3.Name</string>                 </ArrayOfString>             </value>         </setting>         <setting name='blah' serializeAs='String'>             <value>sajksjaksj</value>         </setting>     </Namespace.Properties.Settings> </applicationSettings> 

I can create a string array from this in a bit of a kak handed way:

List<String> values = new List<string>(elementValue.ValueXml.InnerText.Split(new string[]{' ',Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries )); 

but I wonder if there is a nice way that I’m missing that I can get my settings to be read and converted into objects of the right type in the same way that they are when the standard app.config file is read.

Please tell me there is…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:45:26+00:00Added an answer on May 11, 2026 at 5:45 am

    The way that I’ve done this in the past is use a custom configuration section and implement an IConfigurationSectionHandler for the section. You still have to do all of the parsing inside the configuration section handler, but it makes it easy to get the information in the configuration section in the form you want it in your application. There is a How To article on MSDN that goes through the process of creating such a handler.

    Below is an example of one that I’ve used:

    usage:

    Dictionary<string,AdministrativeRole> roles         = ConfigurationManager.GetSection('roles')              as Dictionary<string,AdministrativeRole>; 

    web.config:

    <configuration>    <configSections>       <section name='roles'                type='com.example.RolesDefinitionHandler, com.example' />    </configSections>    <roles>        <role name='Administrator' group='domain\group-name' />        ...    </roles> </configuration> 

    code:

    public class RolesDefinitionHandler : IConfigurationSectionHandler {     private static readonly string ROLE_SECTION_NAME = 'role';     private static readonly string ROLE_SECTION_NAME_ATTRIBUTE = 'name';     private static readonly string ROLE_SECTION_GROUP_ATTRIBUTE = 'group';      private Dictionary<string, AdministrativeRole> ReadConfiguration( XmlNode section )     {         Dictionary<string, AdministrativeRole> roles = new Dictionary<string, AdministrativeRole>();         foreach (XmlNode node in section.ChildNodes)         {             if (node.Name.Equals( ROLE_SECTION_NAME, StringComparison.InvariantCultureIgnoreCase ))             {                 string name = (node.Attributes[ROLE_SECTION_NAME_ATTRIBUTE] != null) ? node.Attributes[ROLE_SECTION_NAME_ATTRIBUTE].Value.ToLower() : null;                 if (string.IsNullOrEmpty( name ))                 {                     throw new ConfigurationErrorsException( 'missing required attribute ' + ROLE_SECTION_NAME_ATTRIBUTE );                 }                  string group = (node.Attributes[ROLE_SECTION_GROUP_ATTRIBUTE] != null) ? node.Attributes[ROLE_SECTION_GROUP_ATTRIBUTE].Value.ToLower() : null;                 if (string.IsNullOrEmpty( group ))                 {                     throw new ConfigurationErrorsException( 'missing required attribute ' + ROLE_SECTION_GROUP_ATTRIBUTE );                 }                  if (roles.ContainsKey( name ))                 {                     throw new ConfigurationErrorsException( 'duplicate ' + ROLE_SECTION_NAME + ' for ' + name );                 }                  roles.Add( name, new AdministrativeRole( name, group ) );             }             else             {                 throw new ConfigurationErrorsException( 'illegal node ' + node.Name );             }         }          return roles;     }      #region IConfigurationSectionHandler Members      public object Create( object parent, object configContext, System.Xml.XmlNode section )     {         return ReadConfiguration( section );     }      #endregion } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DLL that is written in C++ and I want to suppress
I have a fortran dll, and I want to know the assemblies that it
I have a dll that comes in both 32bit and 64bit version. My .NET
I have a .Net DLL that I created that implements a WCF client that
we have a C++ Win32 DLL that reads data from Excel. The application uses
I have a DLL that I inject into another process but I want to
I have a dll which includes a function called ReadPort that reads data from
I have an dll written in C++, and I want to call it from
I have a basic question. 1- I want to use Science.dll provided at http://www.sciencecode.com/
Is there a simple way to read from the global application.exe.config file from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.