Cant read app.config

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

    #1

    Cant read app.config

    I added an app.config file to my application. (c#.net component dll)

    <?xml version="1.0" encoding="utf-8"?>
    <configuratio n>

    <appSettings>
    <add key="username" value="xx" />
    <add key="password" value="xx" />
    </appSettings>
    </configuration>

    I then try to read it in my code as:

    _username = ConfigurationSe ttings.AppSetti ngs["username"].ToString();

    The only using reference i have is using System; and
    System.Configur ation;

    I get an error when trying to read it saying the value is null.
    (running my application in debug mode. This component is being called
    by an ASP.NET application also running in debug under the same
    session)

    What am i doing wrong here? Iv read a lot of forums and searched all
    over google but ims till very confused.

    Should i do anything with the app.config file? Do i have to name it
    something else or move it into the bin folders?

    Any help would be appreciated.
  • Peter Rilling

    #2
    Re: Cant read app.config

    DLLs to not use the config files. So, make sure the config file for the
    appliction (.EXE) has the necessary config settings.


    "MrFile" <webcontact@yah oo.com> wrote in message
    news:9a279ddf.0 408170825.529d3 4@posting.googl e.com...[color=blue]
    > I added an app.config file to my application. (c#.net component dll)
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <configuratio n>
    >
    > <appSettings>
    > <add key="username" value="xx" />
    > <add key="password" value="xx" />
    > </appSettings>
    > </configuration>
    >
    > I then try to read it in my code as:
    >
    > _username = ConfigurationSe ttings.AppSetti ngs["username"].ToString();
    >
    > The only using reference i have is using System; and
    > System.Configur ation;
    >
    > I get an error when trying to read it saying the value is null.
    > (running my application in debug mode. This component is being called
    > by an ASP.NET application also running in debug under the same
    > session)
    >
    > What am i doing wrong here? Iv read a lot of forums and searched all
    > over google but ims till very confused.
    >
    > Should i do anything with the app.config file? Do i have to name it
    > something else or move it into the bin folders?
    >
    > Any help would be appreciated.[/color]


    Comment

    • José Joye

      #3
      Re: Cant read app.config

      According to your post, you are dealing with ASP.NET.
      Therefore, you need to place an <appSettings> section in your Web.Config
      file.

      By the way, if you really need to dedicate an config file to a dll (and not
      using the .exe.config), you will need to load the dll in a separate
      AppDomain and provide the config file before loading the appDomain.

      José
      "MrFile" <webcontact@yah oo.com> wrote in message
      news:9a279ddf.0 408170825.529d3 4@posting.googl e.com...[color=blue]
      > I added an app.config file to my application. (c#.net component dll)
      >
      > <?xml version="1.0" encoding="utf-8"?>
      > <configuratio n>
      >
      > <appSettings>
      > <add key="username" value="xx" />
      > <add key="password" value="xx" />
      > </appSettings>
      > </configuration>
      >
      > I then try to read it in my code as:
      >
      > _username = ConfigurationSe ttings.AppSetti ngs["username"].ToString();
      >
      > The only using reference i have is using System; and
      > System.Configur ation;
      >
      > I get an error when trying to read it saying the value is null.
      > (running my application in debug mode. This component is being called
      > by an ASP.NET application also running in debug under the same
      > session)
      >
      > What am i doing wrong here? Iv read a lot of forums and searched all
      > over google but ims till very confused.
      >
      > Should i do anything with the app.config file? Do i have to name it
      > something else or move it into the bin folders?
      >
      > Any help would be appreciated.[/color]


      Comment

      Working...