Windows Azure - CloudStorageAccount 解析错误
本文关键字:错误 CloudStorageAccount Azure Windows | 更新日期: 2023-09-27 17:57:14
当我尝试获取帐户时,我收到以下错误:
System.Runtime.InteropServices.SEHException
配置中的连接包括:
<?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"));
如果 Azure
代码在没有 Azure 应用结构或存储帐户上下文的情况下在本地运行,通常会发生此错误。 即角色环境不可用。
检查是否未在正常 ASP.net 上下文的上下文中运行代码。如果 CloudProject 不是启动项目,并且您直接启动了角色项目,则可能会发生这种情况。
- 以管理员身份运行 Visual Studio。
- 确保 Azure 开发存储模拟器正在运行。
- 将云项目设置为启动项目。
- 再次验证是否
RoleEnvironment.IsAvailable
。
要验证是否使用此代码,请执行以下操作:
CloudStorageAccount account = null;
if (RoleEnvironment.IsAvailable)
{
account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
// also try
// account = CloudStorageAccount.DevelopmentStorageAccount;
}
else
{
// not in cloud context.
}