none
Why wont my web application read my DataAccessLayer.dll.config file? RRS feed

  • Question

  • I'm trying to use application settings with a C#.NET project I am working on. But I can't seem to get it to return anything other then the default values. Through the project properties I've added a single setting, DBConnectionString, and set its value to a connection string I want to use. Its scope is set to "application".

    Doing this created a number of files including Settings.settings, Settings.Designer.CS, and app.config. The Settings class then has custom, type safe, properties that can be used to set and retrieve each setting. The app.config file is a XML file that stores the actual settings values.

    When I build my project it looks like the app.config file is copied to the target directory as DataAccessLayer.dll.config. My web application runs fine and is able to use the default connection string.

    Next I tried to edit the DataAccessLayer.dll.config file to change the connection string. I ran my web application again, but it continued to use the default value. (Files in \bin deploy folder).

    This project is a class library that use to a Web project and sometimes the connection string can changes.

    Monday, June 8, 2015 11:29 PM

Answers

  • "When I build my project it looks like the app.config file is copied to the target directory as DataAccessLayer.dll.config."

    Class libraries do not have config files that will be read by the config subsystem.  As such if you put the Settings stuff in a class library then the entries won't be read at runtime because DLLs don't have config files. 

    If this is a web application then at runtime all the settings must reside in web.config.  For a Windows app the settings need to reside in <app>.exe.config. If you are defining the settings via a class library then you will need to manually move the settings to the web.config/<app>.exe.config file.

    An alternative approach in the rare cases where you do want to have a library-level config is to use the Configuration class to dynamically load your config.  However this will still not allow your custom config to be used by any code that is outside your control (i.e. Settings designer).  So if you want to use the Settings designer and types then the entries need to be in root config and not .dll.config.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Thursday, June 11, 2015 5:03 PM
    Moderator

All replies

  • Hello Jesus,

    >>Its scope is set to "application".

    As far as I know, the application scope is read-only, please try to set it to user scope if you would change it.

    >> Next I tried to edit the DataAccessLayer.dll.config file

    The actual value should be stored in a separate folder(not the application directory). Check this thread about how to get the location: https://social.msdn.microsoft.com/Forums/vstudio/en-US/8241e079-2514-4945-a9d5-47a4e9f2793d/userconfig-location.

    For your case, I suggest you could set it to user scope and edit the configuration by using code rather than edit the config file(the on in application diecrtory) directly.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 10, 2015 5:21 AM
    Moderator
  • "When I build my project it looks like the app.config file is copied to the target directory as DataAccessLayer.dll.config."

    Class libraries do not have config files that will be read by the config subsystem.  As such if you put the Settings stuff in a class library then the entries won't be read at runtime because DLLs don't have config files. 

    If this is a web application then at runtime all the settings must reside in web.config.  For a Windows app the settings need to reside in <app>.exe.config. If you are defining the settings via a class library then you will need to manually move the settings to the web.config/<app>.exe.config file.

    An alternative approach in the rare cases where you do want to have a library-level config is to use the Configuration class to dynamically load your config.  However this will still not allow your custom config to be used by any code that is outside your control (i.e. Settings designer).  So if you want to use the Settings designer and types then the entries need to be in root config and not .dll.config.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Thursday, June 11, 2015 5:03 PM
    Moderator