Tuesday, 28 March 2017

asp.net - 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?



Answer



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


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...