azureazure-web-rolesazure-cloud-servicesazure-role-environment

Cannot access RoleEnviroment when running multiple Sites inside Cloud Service


I have got an existing solution which uses settings from RoleEnviroment in both the WebRole.OnStart and Global.asax Application_Start handlers. (This has been running well for months)

This all works fine when I have just one Site inside my role:

<WebRole name="WebRole" vmsize="ExtraSmall">
    <Runtime executionContext="elevated" />
    <Sites>
      <Site name="Web1" physicalDirectory="..\..\..\Web1\">
        <Bindings>
          <Binding name="HTTP" endpointName="Public HTTP" hostHeader="web1.com" />
        </Bindings>
      </Site>
    </Sites>

However when I add my second site, neither site can access RoleEnviroment??

<WebRole name="WebRole" vmsize="ExtraSmall">
    <Runtime executionContext="elevated" />
    <Sites>
      <Site name="Web1" physicalDirectory="..\..\..\Web1\">
        <Bindings>
          <Binding name="HTTP" endpointName="Public HTTP" hostHeader="web1.com" />
        </Bindings>
      </Site>
      <Site name="Web2" physicalDirectory="..\..\..\Web2\">
        <Bindings>
          <Binding name="HTTP" endpointName="Public HTTP" hostHeader="web2.com" />
        </Bindings>
      </Site>
    </Sites>

I have tested this in the local azure emulator (full) and it works fine, but when deployed to an actual web role it throws:

[SEHException (0x80004005): External component has thrown an exception.]
   RdGetApplicationConfigurationSetting(UInt16* , UInt16** ) +0
   RoleEnvironmentGetConfigurationSettingValueW(UInt16* pszName, UInt16* pszDest, UInt64 cchDest, UInt64* pcchRequiredDestSize) +73
   Microsoft.WindowsAzure.ServiceRuntime.Internal.InteropRoleManager.GetConfigurationSetting(String name, String& ret) +133
   Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(String configurationSettingName) +109
   Web1.Installer.Install(IWindsorContainer container, IConfigurationStore store) in c:\projects\Webs\Web1\Installer.cs:21

I have checked that the setting I am trying to access is there. When I remove the second Site it works fine. When I remove the first Site it also works fine. It looks to me like there is an issue with Azure providing access to the RoleEnviroment for web roles in multiple instances.


Solution

  • Okay, so after working on this for almost 2 days. The issue turned out to be mismatching Azure SDK version assemblies on the projects.

    The older Site had Azure SDK 2.4, and for some reason the newer Site had SDK 2.3, this meant the RoleEnvironment could not be found when there was two sites (both version of the assembly) deployed.

    I assume this is because they are looking for the RoleEnvironment differently, or are conflicting in how they access it.

    I've read that this may be related to the 'Rd' environment variables that may cause RoleEnvironment to be IsAvailable = false.

    So guys: Check your Azure SDK assembly versions are sync if you encounter this issue!