I want to use an Application Configuration file (App.config) to store the
connection string for a .Net Class Library project.

This is the App.Config file...

<?xml version="1.0" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="MyConnectionString" />
</appSettings>
</configuration>

...and this is the code I'm using to access the setting...
dim str as string =
System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString

...but this is the error I'm getting...
An unhandled exception of type 'System.NullReferenceException' occurred in
MyLibrary.dll

Any ideas why ?
Craig

RE: Using an Application Configuration file by SureshBojja

SureshBojja
Fri Jul 22 05:10:01 CDT 2005

Hi Criag

Actually you cannot have a config file for dll files.

even though, if you set the config file for dll, it will take the value from
application config file where u are refering the dll.

for example:
if a.dll have app.config file and a.dll is refered in b.exe, the
system.configuration.configurationsettings.appsettings.get of a.dll will
search in b.exe config file.

"Craig HB" wrote:

> I want to use an Application Configuration file (App.config) to store the
> connection string for a .Net Class Library project.
>
> This is the App.Config file...
>
> <?xml version="1.0" ?>
> <configuration>
> <appSettings>
> <add key="ConnectionString" value="MyConnectionString" />
> </appSettings>
> </configuration>
>
> ...and this is the code I'm using to access the setting...
> dim str as string =
> System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString
>
> ...but this is the error I'm getting...
> An unhandled exception of type 'System.NullReferenceException' occurred in
> MyLibrary.dll
>
> Any ideas why ?
> Craig
>

RE: Using an Application Configuration file by CraigHB

CraigHB
Fri Jul 22 05:35:02 CDT 2005

It worked ! -- thanks, Suresh

I moved the app.config file to the "b.exe" project and it worked