Get AppSettings Section

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Get AppSettings Section

    Hello,

    I am getting the AppSettings section as follows:

    AppSettingsSect ion appSettingSecti on =
    (AppSettingsSec tion)Configurat ionManager.GetS ection("appSett ings");

    However, I am getting the following error:

    Unable to cast object of type
    'System.Configu ration.KeyValue InternalCollect ion' to type
    'System.Configu ration.AppSetti ngsSection'.

    What am I doing wrong?

    Thanks,

    Miguel
  • Mark Rae [MVP]

    #2
    Re: Get AppSettings Section

    "shapper" <mdmoura@gmail. comwrote in message
    news:464a58cb-3be7-4a7f-b55a-0c476f474b38@a2 9g2000pra.googl egroups.com...
    What am I doing wrong?
    Mismatching objects...

    System.Configur ation.Configura tion config =
    ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);
    AppSettingsSect ion appSettingSecti on =
    (AppSettingsSec tion)config.Get Section("appSet tings");


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • shapper

      #3
      Re: Get AppSettings Section

      On Nov 6, 1:39 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
      "shapper" <mdmo...@gmail. comwrote in message
      >
      news:464a58cb-3be7-4a7f-b55a-0c476f474b38@a2 9g2000pra.googl egroups.com...
      >
      What am I doing wrong?
      >
      Mismatching objects...
      >
      System.Configur ation.Configura tion config =
      ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);
      AppSettingsSect ion appSettingSecti on =
      (AppSettingsSec tion)config.Get Section("appSet tings");
      >
      --
      Mark Rae
      ASP.NET MVPhttp://www.markrae.net
      But I am building a custom Web.Config section and I am using the
      following to get my section:

      object projSetings =
      ConfigurationMa nager.GetSectio n("projSettings ");

      So I though I could use it directly only by setting the type. I am
      going to try your approach ...

      I am having troubles with my custom configuration section and no one
      is able to answer me ... I will try something else and probably post a
      new thread about it.

      Comment

      • shapper

        #4
        Re: Get AppSettings Section

        On Nov 6, 1:39 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
        "shapper" <mdmo...@gmail. comwrote in message
        >
        news:464a58cb-3be7-4a7f-b55a-0c476f474b38@a2 9g2000pra.googl egroups.com...
        >
        What am I doing wrong?
        >
        Mismatching objects...
        >
        System.Configur ation.Configura tion config =
        ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);
        AppSettingsSect ion appSettingSecti on =
        (AppSettingsSec tion)config.Get Section("appSet tings");
        >
        --
        Mark Rae
        ASP.NET MVPhttp://www.markrae.net
        Ooops, I am getting the following error:

        "exePath must be specified when not running inside a stand alone exe"

        In: System.Configur ation.Configura tion config =
        ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);

        Any idea?

        Thanks,
        Miguel

        Comment

        • Mark Rae [MVP]

          #5
          Re: Get AppSettings Section

          "shapper" <mdmoura@gmail. comwrote in message
          news:7cd059fb-0b48-4bea-a566-64ff033c917b@p3 1g2000prf.googl egroups.com...
          Ooops, I am getting the following error:
          >
          "exePath must be specified when not running inside a stand alone exe"
          >
          In: System.Configur ation.Configura tion config =
          ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);
          >
          Any idea?
          Yes - my fault, I'm afraid...

          System.Configur ation.Configura tion config =
          ConfigurationMa nager.OpenWebCo nfiguration(Con figurationUserL evel.None);


          --
          Mark Rae
          ASP.NET MVP


          Comment

          • shapper

            #6
            Re: Get AppSettings Section

            On Nov 6, 2:53 pm, "Mark Rae [MVP]" <m...@markNOSPA Mrae.netwrote:
            "shapper" <mdmo...@gmail. comwrote in message
            >
            news:7cd059fb-0b48-4bea-a566-64ff033c917b@p3 1g2000prf.googl egroups.com...
            >
            Ooops, I am getting the following error:
            >
            "exePath must be specified when not running inside a stand alone exe"
            >
            In:  System.Configur ation.Configura tion config =
            ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None);
            >
            Any idea?
            >
            Yes -  my fault, I'm afraid...
            >
            System.Configur ation.Configura tion config =
            ConfigurationMa nager.OpenWebCo nfiguration(Con figurationUserL evel.None);
            >
            --
            Mark Rae
            ASP.NET MVPhttp://www.markrae.net
            There is not OpenWebConfigur ation method in
            ConfigurationMa nager ... :-)

            Comment

            • Mark Rae [MVP]

              #7
              Re: Get AppSettings Section

              "shapper" <mdmoura@gmail. comwrote in message
              news:d265cb6b-ccb4-4fcf-9eb4-94af27b26a6f@d3 6g2000prf.googl egroups.com...
              There is not OpenWebConfigur ation method in ConfigurationMa nager ... :-)



              --
              Mark Rae
              ASP.NET MVP


              Comment

              • =?Utf-8?B?SmltYm8gTQ==?=

                #8
                Re: Get AppSettings Section

                I've been trying to use this technique to get the appSettings section, but I
                cannot figure out how to cast the result of GetSection(). Any ideas? I keep
                coming back to the same tail chasing.

                Simply put, how does one access the appSettings section using
                WebConfiguratio nManager?

                "Mark Rae [MVP]" wrote:
                "shapper" <mdmoura@gmail. comwrote in message
                news:d265cb6b-ccb4-4fcf-9eb4-94af27b26a6f@d3 6g2000prf.googl egroups.com...
                >
                There is not OpenWebConfigur ation method in ConfigurationMa nager ... :-)
                >

                >
                >
                --
                Mark Rae
                ASP.NET MVP

                >
                >

                Comment

                • =?Utf-8?B?SmltYm8gTQ==?=

                  #9
                  Re: Get AppSettings Section

                  My bad...I was looking in the wrong namespace...was looking in
                  System.Web.Conf iguration instead of System.Configur ation. Slapping my own
                  paw...

                  "Mark Rae [MVP]" wrote:
                  "shapper" <mdmoura@gmail. comwrote in message
                  news:d265cb6b-ccb4-4fcf-9eb4-94af27b26a6f@d3 6g2000prf.googl egroups.com...
                  >
                  There is not OpenWebConfigur ation method in ConfigurationMa nager ... :-)
                  >

                  >
                  >
                  --
                  Mark Rae
                  ASP.NET MVP

                  >
                  >

                  Comment

                  Working...