سؤال

I'm getting the following error when I try to get the account:

System.Runtime.InteropServices.SEHException

The Conn in configurations are:

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="WindowsAzureProject3" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*" schemaVersion="2013-10.2.2">
  <Role name="manager">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Conn" value="DefaultEndpointsProtocol=https;AccountName=name;AccountKey=key"></Setting>
    </ConfigurationSettings>
  </Role>
  <Role name="detectrod">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="DataConnectionString" value="DefaultEndpointsProtocol=https;AccountName=name;AccountKey=key"></Setting>
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

(the account keys are correct)

and the line with error is:

var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
هل كانت مفيدة؟

المحلول

This error typically happens if your azure code is locally run without the context of azure app fabric or storage account. i.e. A ROLEENVIRONMENT is not available.

Check if you're not running the code under the context of normal ASP.net context. This could happen if CloudProject is not the startup project and if you directly started the role project.

  1. Run Visual Studio as Admin.
  2. Ensure Azure Dev Storage emulators are running.
  3. Set Cloud project as startup project.
  4. Verify again if RoleEnvironment.IsAvailable.

to verify use this code:

CloudStorageAccount account = null;

if (RoleEnvironment.IsAvailable)
{
 account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));

 // also try
 // account = CloudStorageAccount.DevelopmentStorageAccount;
}
else
{
 // not in cloud context.
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top