none
Assembly with own configuration file

    Question

  • Hi,

    in .Net 1.x you could use configuration files (.config) with application projects (.exe) or web applications.
    Now with .Net 2.0 (and Visual Studio 2005) it should also be possible to assign a configuration file to specific assemblies. But I have some trouble using this feature:


    Assuming my project use 2 distinct Assemblies, the main one, wich is a ASP.NET web application using its web.config, and a DLL for the Business Layer (BL.dll) using its own App.config. The BL.dll is referenced and used within the web project.


    Within the BL.dll I try to access the configuration by this way:

    Configuration config = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);

    But the Location property of the assembly is the path where it has been shadow-copied by ASP.NET (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ ..) and therefore no config file can be found (because the config file has not been copied there).


    What is the right way to use such a separate config file for different assemblies?

    1.
    Is there any way to automatically copy the configuration file (BL.dll.config) to the execution folder (bin) of the web project (according to its reference to the BL.dll)?

    2. How can I access the config files?

    Thanks..



    Tuesday, May 22, 2007 11:57 AM

Answers

  • Hi slein,

       The config files are assigned per application domain. And There is no built-in support for DLL or assembly based configuration file in .Net

       There is a reference on how to use per-assembly configuration files with appSettings-like configuration elements.

       A sample that uses per-assembly config files: http://www.bearcanyon.com/dotnet/#AssemblySettings

       Hope it can help you. 

    Thanks.

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thursday, May 24, 2007 8:49 AM

All replies

  • Hi slein,

       The config files are assigned per application domain. And There is no built-in support for DLL or assembly based configuration file in .Net

       There is a reference on how to use per-assembly configuration files with appSettings-like configuration elements.

       A sample that uses per-assembly config files: http://www.bearcanyon.com/dotnet/#AssemblySettings

       Hope it can help you. 

    Thanks.

     

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thursday, May 24, 2007 8:49 AM
  • So how does this answer help with the shadow copy problem?  The config file will not be copied right?
    Monday, February 16, 2009 8:45 PM
  • Update - the Assembly.Codebase property will give you the location of the assembly before the shadow copy.  Then you can programmatically load a configuration file as above.  (The Assembly.Location property described above will give you the path to the shadow copy, but the config file will not be copied to that path.)
    • Proposed as answer by xiondavis Monday, February 23, 2009 8:42 PM
    Monday, February 23, 2009 8:41 PM