Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting SEHException when calling RoleEnvironment.GetConfigurationSettingValue("MYKEY")?

Tags:

c#

azure

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

like image 387
Kori Avatar asked Jun 02 '10 13:06

Kori


3 Answers

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.

like image 119
David Makogon Avatar answered Oct 30 '22 05:10

David Makogon


To follow up on that, just in case someone runs into the same problem again, it might also be the case that for whatever reason one of your deployments got stuck in the compute emulator.

What happened to me was that I had a webrole containing multiple websites, each bound to a different hostname. Say: localhost and test.localhost. Normally, you would access these at localhost:81 and test.localhost:81. For some strange reason though, one deployment got into a weird state where it would be listed in the compute emulator, with no Visual Studio debugging it, it would say "Role Instance destroyed" or something along those lines.. This deployment still had the websites deployed in IIS. I then, without knowing about this buggy deployment, accessed the default urls, ie. test.localhost:81 which would load up the old deployment files. The (old) site worked until I opened a page that actually used the RoleEnvironment.GetConfigurationSettingValue method, and only then I got that exception. It was really frustrating as this boggus deployment obvioulsy didn't hit any breakpoints nor breaked on exceptions, yet it looked exactly as the site I've been working on..

When I realised this, I opened the hostnames under the new port and there the pages worked as expected. Once I removed this buggy deployment from the compute emulator the IIS websites also got deleted and thankfully the ports are now available for use as expected..

like image 30
karel_evzen Avatar answered Oct 30 '22 03:10

karel_evzen


Removing the <Sites> tag in the ServiceDefinition.csdef file could be a workaround for you as was for us but then your site will not be deployed to Full IIS on the Cloud. We are using 1.7 of the SDK.

So in summary: RoleEnvironment.IsAvailable = False with this included in the ServiceDefinition.csdef with an instance count of 1 I might add.

<Sites>
      <Site name="Blah">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Http" />
          <Binding name="Endpoint1" endpointName="Https" />
        </Bindings>
      </Site>
</Sites> 

Remove the <Sites> node and deploy and you might find that now RoleEnvironment.IsAvailable = True.

There are very little logs about what is actually happening - the website is running fine, there are no warnings except the usual you only have 1 instance why not deploy 2 and the site is up and running fine.

This is a recent issue and I believe there must be some changes made in that msshrtmi.dll. It could log a little more of what might actually be the problem if the RoleEnvironment is not available.

like image 29
Andy A. Avatar answered Oct 30 '22 04:10

Andy A.