When you write a web role requiring application specific configuration (like assembly binding), you may have a hard time trying to figure out which app configuration file should be used and how to get it deployed and used in your role. This issue has been hit by many developers and raised in many blogs & forums:
The key point to remember is that full IIS web role entry point (code implemented in WebRole.cs) is loaded into the WaIISHost.exe process and not w3wp.exe. Therefore, you can't expect settings defined in web.config to be used in you role entry point.There are 2 solutions to this issue :
These are the steps you can use for the second option in Visual Studio :
Alternatively to the above approach, you can use a "Before build" action to copy the web.config to bin\<webrole name>..dll.config :
copy $(ProjectDir)Web.config $(TargetDir)$(TargetFileName).config
Using the context menu, you'll then need to include in the project the bin\<webrole name>.dll.config. With this approach, you'll be able to set all you settings in a single file (web.config).
With the above steps, you should end up with the web role config file copied to the /bin directory of your webrole (E:\sitesroot\0\bin). In case, it isn't, you may also check that the configuration file is present in the package created (open the cspkg file as a zip file and confirm that the config file is present under the path : WindowsAzure1.cspkg\WebRole1_<ID>.cssx\approot\bin\).I would like to thank Mr Claus Nielsen for having reported the issue and spending time to troubleshoot it with Microsoft Support…
A note for anybody trying to use the pre-build command above, ensure the commands are encased in quotes if your project directory has spaces, else the command will not work.
copy "$(ProjectDir)Web.config" "$(TargetDir)$(TargetFileName).config"