Using an Application Configuration file

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
 
G

Guest

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

Guest

It worked ! -- thanks, Suresh

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

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