Cant read app.config

M

MrFile

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

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

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

I then try to read it in my code as:

_username = ConfigurationSettings.AppSettings["username"].ToString();

The only using reference i have is using System; and
System.Configuration;

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.
 
P

Peter Rilling

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

José Joye

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é
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top