Solved

Unable to cast to type AppSettingsSection

Posted on 2011-03-20
1
2,443 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
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
We had a requirement to extract data from a SharePoint 2010 Customer List into a CSV file and then place the CSV file into a directory on the network so that the file could be consumed by an AS400 system. I will share in Part 1 how to Extract the Da…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now