Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.config with app.config in .dll

I just inherited a very old ASP.NET 2.0 web application.

In the application it has SEVERAL support class library projects. In the DataAccess class library, is an app.config (and setting.settings file) with a connection string named ConnString1.

I always thought that a .DLL couldn't have a app.config/setting.settings file (or at least you can include them but they won't be used), so this is what is confusing to me.

The web.config also has a connection string named ConnString1 with the same server login credentials, but a different server name.

When I run the application from Visual Studio DEBUG, it uses the connection string that is located in the app.config/settings file, and not the one defined in the web.config/machine.config.

I thought .DLLs wouldn't do this, but use the web.config instead?

However, when I pushed this application in RELEASE mode to our production server (in test website), it seems to be using the correct connection string in the web.config.

Can anyone explain this?

like image 535
Sean Avatar asked Nov 04 '25 11:11

Sean


2 Answers

There's got to be something that is confusing you to think that the config file that's a part of that DLL is being used - as opposed to the applications (entry point's) config file (yourapp.exe.config or web.config). Maybe that conn string is hard-coded somewhere for the use in debug mode, e.g. by using conditional compilation via "#if DEBUG" preprocessor directive (so, maybe search for "#if DEBUG" across your solution to see if this particular thing is happening).

MSDN article about app settings

See the yellow "Note" in the section "Creating Application Settings at Design Time": "Because there is no configuration file model for class libraries, application settings do not apply for Class Library projects."

I found the issue:

In the above example, I am using the web.config/machine.config to set the connection string for the application.

If the connection string isn't defined in the web.config, it defaults to the machine.config. If the connection string isn't defined in the machine.config, it will use the app.config setting found in the .dll.

It's important to note, that placing the connection string in the machine.config, it must be defined in the correct Framework/CONFIG.

On my development machine, the connection string wasn't defined in the web.config but in the environment.config, but in the Framework64/CONFIG -- however, the application is compiled in 32-bit, thus, the reason for using Framework/CONFIG that did not have the connection string defined in it and causing it to default to the app.config in the class library.

I hope that explains that?

like image 42
Sean Avatar answered Nov 06 '25 03:11

Sean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!