views:

79

answers:

3

I am developing a custom HttpHandler, to do so I write a C# Class Library and compile to DLL.

As part of this I have some directory locations which I want not hard coded in the app, so i'm trying to put it in the app.config which I've used before.

Before this has worked by just going building the app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="Share" value="C:\...\"/>
  </appSettings>
</configuration>

And then obtaining this in code like:

var shareDirectory = ConfigurationManager.AppSettings["Share"];

But when I compile it and put it in the bin folder for the webservice, it keeps getting null for shareDirectory, probably because it can't find app.config. So how do I make sure this is included so I don't have to hard code my direcotry locations? I notice it will essentially after compiled we get the assembly.dll and the assembly.dll.config which is the app.config file, so it's definetly there in the bin folder!

+2  A: 

You need to put the configuration in your web.config file, not in assembly.dll.config: .NET does not (by design) read assembly.dll.config files.

Dean Harding
+3  A: 

That is because your web service uses web.config

Aren
+1  A: 

You're probably confusing the scope of your class library.

Remember, your config, be it web.config, or app.config, is the config present in the HOSTING application. In this case your hosting application is the WebService, hosted of course by IIS, so your config file is the web.config.

If you had a console app which somehow used that class library (though probably not in an http handler context), then the config would be the app.config in the console app, not the app.config in your class library.

andy