简体   繁体   中英

Why can't I use my dll that is referenced config file

I would like to ask this question it is crazy that inside the dll code I can't reference the dll.config file and its only compiled into the exe and copied to any other project to the solution.

Haven't you ever wondered when you created a dll file ( DataAccess.dll ) for instance which you would like to use for different applications with different sql connection strings but when you build the solution it creates a DataAccess.dll.config file but never copies it into any other solution that is of either a Winforms or Windows service. It just stays there.

If your try to copy the config file over and change the values, you only get what was originally compiled at the time even thought it looks like in the dll your accessing the config settings with intellisense, the values are ignored after compilation. If you open your dll in notepad you will see your settings are compiled into the dll itself.

It boggles my mind that I would have to copy the values from the config file manually into the exe's config file to access configuration settings in an object oriented intellisense manager, except I have to use a hard coded open config file by path and search threw elements

What is the deal? No answer for what to me seams what would be a much easier way of doing things, let alone realistic and by design

A dll does not have an associated config file in .NET.

Why? Because a dll is not stand alone - it runs in the context of an executable.

The config that will be read is the one associated with the executable.

You need to change the .exe.config file in order for the configuration values to be updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM