6
votes

I'm implementing the combined web/worker role scenario as described here where you simply add the following to your worker role:

public override void Run()
{
    // This is a sample worker implementation. Replace with your logic.
    Trace.WriteLine("WorkerRole1 entry point called", "Information");
    while (true)
    {
        Thread.Sleep(10000);
        Trace.WriteLine("Working", "Information");
    }
}

The problem, as noted in the post's comments, is that this worker process cant read web.config so you have to add an app.config. It is also noted that app.config does not get deployed automatically.

So my question is how do I configure my project so app.config will get deployed?

I've added app.config to my project, set the Build Action to "Content", and "Copy always"

THIS WORKS FINE IN THE EMULATOR, but not when deployed to Azure.

Note: I noticed in the emulator a projectname.dll.config is created, but not when deployed to Azure. I'm using VS2010, Windows Azure Tools 2011

I know some will suggest using the .cscfg file instead, but many of my components get their settings from web.config/app.config: Elmah, Transient Fault Handling Client, Diagnostics, Email, etc...

3

3 Answers

3
votes

Please read thoroughly this blog post. It explains in great details what is happening in Windows Azure Web Role with Full IIS.

What you need to do, is to add a WaIISHost.exe.config file (with copy to output = copy always). And put all the configurations you need in that file. This is because, your code (RoleEntryPoint) lives in WaIISHost.exe process, and not your pdojectName.dll process.

3
votes

For me using Azure SDK 1.8 and deploying my Web Worker Role from the Visual Studio using publish, I had to include a config file, named. ProjectName.Dll.config with my settings. The configuration from app.config is not picked up by the web role when running in windows azure. And the app.config file is not converted into a ProjectName.Dll.config and added automatically to the bin folder of the deployment package, so you have to create it by hand and set it to copy always.

2
votes

I'm using Azure SDK 2.0 and OS Family 3, and has been very confused about this. So I created a MVC 4.0 website with all 4 config files suggested in various answers. That is:

  • Web.config
  • App.config
  • WaIISHost.exe.config
  • [AssemblyName].dll.config

All but Web.config was set to "Copy if newer".

In the configs file I wrote:

  <appSettings>
    <add key="AppSettingFile" value="[NameOfConfigFile]"/>
  </appSettings>

In the WebRole.cs I have the following code:

    public class WebRole : RoleEntryPoint
    {
        public override void Run()
        {
            string appSetting = ConfigurationManager.AppSettings["AppSettingFile"] ?? "No config file found";
            Trace.TraceInformation("Config file: " + appSetting);

            while (true)
            {
                ...
            }
        }
    }

Result when deployed with 4 .config files: "Config file: App.config". So App.config must be the answer, right?

Wrong! Result when deployed with only Web.config and App.config: "Config file: No config file found". Hmm wierd.

Result when deployed with Web.config, App.config and [AssemblyName].dll.config: "Config file: [AssemblyName].dll.config". So [AssemblyName].dll.config must be the answer, right?

Wrong! Result when deployed with only Web.config and [AssemblyName].dll.config: "Config file: No config file found". WTF!

Result when deployed with only Web.config and WaIISHost.exe.config: "Config file: No config file found".

Result when deployed with Web.config, App.config and WaIISHost.exe.config: "Config file: No config file found". WTF!

So my conclusion is that you need to have 3 or 4 config files to be able to configure the Worker role of a Web project.

This is clearly a bug. Personally I think the intention from MS was to change from WaIISHost.exe.config to App.config (to align with Worker Roles and .NET in general). But App.config is only used when all 4 .config files exists.

So for now I'm having Web.config and both App.config and [AssemblyName].dll.config, and they contain exactly the same.

Hopefully going forward with Azure SDK 2.x we can use only App.config and Web.config.