3

I'm a bit lost!

I have a dll that uses an xml config file for some db connection info. The dll looks for the xml config file in it's own directory and I can't change the dll at all.

Every time I build the project, I must manually copy the config file into a folder way down somewhere in the Temporary ASP.NET Files folder. (I don't understand this but I can live with this manual change)

The problem is that when I publish the project, I can't figure out where to copy the config file to?

Could someone please point me in the right direction? Or maybe show me a way that I can 'bind' the xml config file to the bin folder???

Vauneen

Khan
  • 516
  • 11
  • 24
Vauneen
  • 147
  • 3
  • 13
  • So this xml file isn't the standard .NET `app.config`? Because if so, it may be that you just need to copy the expected configuration to your `Web.config` file (see my answer). – Kit Roed Jun 15 '12 at 20:39
  • Hi Kit.thanks for your answer. No. i dont think it's the standard .net app.config file. it's named after the dll, but with the extension .config. So: nameofdll.config and it contains xml much like the web.config file but in a node called 'userSettings' which throws this error if i put it in the web.config file 'Unrecognized configuration section userSettings' – Vauneen Jun 15 '12 at 21:55
  • I have one last idea, that your ASP.NET project needs to use a (apparenlty obsolete) `ConfigurationSettings` reference. Check my updated answer. (And see this [answer](http://stackoverflow.com/a/1189369) ) – Kit Roed Jun 18 '12 at 19:59

2 Answers2

3

The .NET config file can be confusing to manage. The way it works in a webapp is that the Web.config will supersede any dependencies' app.config files (which is what I assume you're talking about when you say "DLL".)

Basically, in .NET all config info is pulled from the main app project.

See:

App.config seems to be ignored

and

Configuration from App.config isn't being pulled correctly

and finally:

Does a web.config substitute app.config?

will probably help you figure out what you need to know.

Update: Doing some further searching on your problem, it's possible that the code you're incorporating into the .Net Solution is using the "obsolete" ConfigurationSettings which will require you to add a reference to System.Configuration in your references folder (right-click on the project -> "Add References" and go to the .NET tab and select System.Configuration).

Community
  • 1
  • 1
Kit Roed
  • 5,167
  • 5
  • 30
  • 34
  • Hi Kit. putting the info into web.config doesnt work. i've tried adding it a few ways. i believe that dll will always look for it's config file in it's own directory. so i think my only way to make this work is to figure out where i need to put the config file after publishing. – Vauneen Jun 15 '12 at 22:13
  • @Vauneen Interesting! Perhaps you could check and see where it's looking for sure by using [Process Monitor](http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) and see what path your process is attempting to open? Perhaps this is after the fact as you already seem to see where it's looking... – Kit Roed Jun 17 '12 at 20:15
  • tried with System.Configuration, no luck. I figured the fastest way to get back on track was to ask the guy who built the dll to rather give me one without the config file. So without resolving this issue, i'm back on track. Thanks for ALL your help! – Vauneen Jun 20 '12 at 10:40
1

Set "Copy to Output Directory" to "Copy always" in properties of the configuration. Then Visual Studio will copy the configuration file automatically after each build and it will be properly published as well.

Jakub Linhart
  • 4,062
  • 1
  • 26
  • 42
  • Hi Jakub, thanks for your response. Doing that gets the xml config file published to 'C:\inetpub\wwwroot\BETA\bin' but the error message i get when viewing the built version (i cant get the published version to work at all) shows that the page is looking for the config file here: 'C:\Users\vauneen\AppData\Local\Temp\Temporary ASP.NET Files\root\2a97c644\3fd65c8a\assembly\dl3\5935cc01\0052d185_23eccc01' Do you have any idea why it doesnt look for the config in inetpub? – Vauneen Jun 17 '12 at 17:25
  • The path seems to be an AppDomain.CurrentDomain.DynamicDirectory. Please, could you check it? Please, what is the name of the library (if it is publicly known)? – Jakub Linhart Jun 17 '12 at 18:55
  • Hi Jakub, i've given up on understanding this one. i asked the guy who wrote the dll to give me a version the doesnt require a config file and all is working now with that new dll. Thank you so much for your help! – Vauneen Jun 20 '12 at 10:43