Windows Azure - CloudStorageAccount解析错误

时间:2014-04-07 16:21:26

标签: c# azure azure-sql-database azure-storage

当我尝试获取帐户时,我收到以下错误:

  

System.Runtime.InteropServices.SEHException

配置中的Conn是:

<?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>

(帐户密钥正确无误)

,错误行是:

var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));

1 个答案:

答案 0 :(得分:3)

如果您的azure代码是在没有azure app fabric或存储帐户的上下文的情况下本地运行,则通常会发生此错误。即没有ROLEENVIRONMENT。

检查您是否在普通ASP.net上下文的上下文中运行代码。如果CloudProject不是启动项目并且您直接启动角色项目,则可能发生这种情况。

  1. 以管理员身份运行Visual Studio。
  2. 确保Azure Dev Storage模拟器正在运行。
  3. 将云项目设置为启动项目。
  4. 再次验证RoleEnvironment.IsAvailable
  5. 验证使用此代码:

    CloudStorageAccount account = null;
    
    if (RoleEnvironment.IsAvailable)
    {
     account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
    
     // also try
     // account = CloudStorageAccount.DevelopmentStorageAccount;
    }
    else
    {
     // not in cloud context.
    }