Solved

Unable to cast to type AppSettingsSection

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

12 Experts available now in Live!

Get 1:1 Help Now