IAmGroot
IAmGroot

Reputation: 13855

How do I get my .NET library to inherit its configuration file settings from the requested app?

I compile my .NET Library, and it creates mylib.dll.config.

But when I modify or even delete this file, it is clearly not being used.

My ASP.NET website has the exact same settings in it anyway, so is it possible to inherit the connection string?

That is, the .NET library inherits its connection string from my ASP.NET app configuration.

I call my settings from my library using:

mylib.Properties.Settings.Default.dbConnString;

or

Properties.Settings.Default.dbConnString;

My website has an identical setting:

myweb.Properties.Settings.Default.dbConnString;

The library is running off its compile time settings. Not the web settings.

Upvotes: 0

Views: 529

Answers (2)

granaker
granaker

Reputation: 1328

Your library will use the configuration that is present in the configuration file for the executing assembly. In your case that is your web.config file of the ASP.NET web site.

Upvotes: 1

Stéphane Bebrone
Stéphane Bebrone

Reputation: 2763

At runtime the mylib.dll.config (created by your class library project) will be ignored and it's the Web.config that will be used.

That's the normal behavior for an asp.net web site.

It means that if you add something into your .dll.config file, you'd have to add it to the Web.config file as well.

See this related question.

Upvotes: 4

Related Questions