当我尝试获取帐户时,我收到以下错误:
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"));
答案 0 :(得分:3)
如果您的azure代码是在没有azure app fabric或存储帐户的上下文的情况下本地运行,则通常会发生此错误。即没有ROLEENVIRONMENT。
检查您是否在普通ASP.net上下文的上下文中运行代码。如果CloudProject不是启动项目并且您直接启动角色项目,则可能发生这种情况。
RoleEnvironment.IsAvailable
。验证使用此代码:
CloudStorageAccount account = null;
if (RoleEnvironment.IsAvailable)
{
account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
// also try
// account = CloudStorageAccount.DevelopmentStorageAccount;
}
else
{
// not in cloud context.
}