Solved

Unable to cast to type AppSettingsSection

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

689 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