tags:

views:

264

answers:

1

I'm trying to call RoleEnvironment.GetConfigurationSetting("SOMEKEY") like so:

public partial class AzureBasePage : System.Web.UI.Page
{
    protected ChargifyConnect Chargify
    {
        get {
            if (this._chargify == null) {
                this._chargify = new ChargifyConnect();
                this._chargify.apiKey = RoleEnvironment.GetConfigurationSettingValue("CHARGIFY_API_KEY");
            }
            return this._chargify;
        }
    }
    private ChargifyConnect _chargify = null;
}

My ServiceConfiguration.cscfg key looks like this:

<Setting name="CHARGIFY_API_KEY" value="AbCdEfGhIjKlMnOp" />

And I get this error:

Exception Details: System.Runtime.InteropServices.SEHException: External component has thrown an exception.

[SEHException (0x80004005): External component has thrown an exception.] RoleEnvironmentGetConfigurationSettingValueW(UInt16* , UInt16* , UInt32 , UInt32* ) +0 Microsoft.WindowsAzure.ServiceRuntime.Internal.InteropRoleManager.GetConfigurationSetting(String name, String& ret) +92 Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(String configurationSettingName) +67 ChargifyNET.ChargifyAzurePage.get_Chargify() in C:\NetProjects\ChargifyDotNET\Source\Chargify.NET\ChargifyAzurePage.cs:26 Chargify.Azure._Default.Page_Load(Object sender, EventArgs e) in C:\NetProjects\ChargifyDotNET\Source\Chargify.Azure\Default.aspx.vb:8 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

+2  A: 

You will get the SEHException if you attempt to access RoleEnvironment if you're not running in the dev fabric or Azure fabric. I believe you're inadvertently running your website under the asp.net development server, meaning you're not in the dev fabric (I've confirmed that this will throw an SEHException). In other words, you've either set your website project as the startup project, or you've right-clicked it and told it to run.

You must set the cloud project itself as the startup project, which will then show your website running on port 81 by default. The cloud project is the project that has, as its members, all of your role definitions. You can look at your browser's URL bar and easily tell if you're running in the asp.net dev server, because you'll be on some random port number instead of port 81.

You should make sure you're running in the dev fabric or Azure fabric by checking RoleEnvironment.IsAvailable(). If that's true, you're safe to call anything in RoleEnvironment. If it's false, you're not running within the fabric.

David Makogon
Thanks. That was a good answer, I'll verify - but I'm sure that's it.
Kori
Just another comment as to the resolution of this question, I created a library which needs to run in both Azure and non-Azure environments - so I couldn't reference RoleEnvironment directly. I did however use reflection to determine the value of RoleEnvironment.IsAvailable()
Kori