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.
- Run Visual Studio as Admin.
- Ensure Azure Dev Storage emulators are running.
- Set Cloud project as startup project.
- 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.
}