Using an Application Configuration file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
It worked ! -- thanks, Suresh

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