Solved

Unable to cast to type AppSettingsSection

Posted on 2011-03-20
1
2,737 Views
Last Modified: 2012-05-11
I get "Unable to cast object of type 'System.Configuration.DefaultSection' to type 'System.Configuration.AppSettingsSection'" when I´m trying to get values from a custom config file. Somebody help!!!

Code:
                    ConfigurationFileMap fileMap = new ConfigurationFileMap(CONFIG_PATH);
                    Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
                    value = configuration.AppSettings.Settings[key].Value;

Config File:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="FeedCacheTime" value="300" />
    <add key="FeedPageUrl" value="/_layouts/feed.aspx?" />
    <add key="FeedXsl1" value="/Style Library/Xsl Style Sheets/Rss.xsl" />
    <add key="ReportPath" value="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\SGPT\" />
    <add key="ProjectSite" value="Enabled" />
    <add key="ProjectTemplate" value="proyectoSGPT70" />
    <add key="TestMode" value="Off" />
    <add key="ADRefreshMinutes" value="20" />
    <add key="SGPTWebURL" value="http://ttacsys/" />
    <add key="WebAdmin" value="User=administrator, Password=password" />
    <add key="EstadoProyectoFinalizado" value="Finalizado" />
    <add key="AspectosPositivos" value="Aspectos Positivos" />
    <add key="AscpectosAMejorar" value="Aspectos A Mejorar" />
    <add key="ConnectionString" value="server=ttacsys\OFFICESERVERS;database=SGTIdb ;uid=Franco;pwd=password;" />
    <!--ID item Presupuesto de ProyectoLibreriaTemplates -->
    <add key="IDPresupuestoLibTemplates" value="15" />
  </appSettings>
  <connectionStrings/>
</configuration>
0
Comment
Question by:acsyssa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
lenordiste earned 500 total points
ID: 35176642
you can add this to the configuration file you wish to read:
<configuration>
  <configSections>
    <section name="appSettings"
                type="System.Configuration.AppSettingsSection"/>
  </configSections>
  <appSettings>.....

Open in new window


Once you've done that your code should work fine.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What are MicroServices? 4 67
Shared Service Environment 2 54
asp.net mvc5 6 33
Content of a read only textbox are not being saved in table in asp.net - VB 5 34
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question