Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudConfigurationManager.GetSetting returns null while RoleEnvironment.GetConfigurationSettingValue works as expected

Tags:

startup

azure

I have a small executable I run as part of the startup tasks of my Azure web role. I used RoleEnvironment.GetConfigurationSettingValue to read some settings from the cscfg inside the executable, which worked fine. I was given feedback that it is recommended to use CloudConfigurationManager.GetSetting instead, but when I tried it, the method returned null (setting not found). I can see the settings I'm trying to read are there in the portal.

I saw that some people had a similar issue with CloudConfigurationManager and asked about it: 1. here: CloudConfigurationManager.GetSetting returning null 2. and here: CloudConfigurationManager.GetSetting returns empty string in production?

But the solutions were always about updating the Azure SDK and all references, which doesn't work for me.

(We use Azure SDK v2.0 and all references point to the same version. I also validated this is the version loaded at runtime on the VM)

Thanks in advance for any clues!

like image 506
user1039580 Avatar asked Dec 05 '13 22:12

user1039580


1 Answers

My problem was that the StartUp Project of my solution changed to the WebRole project. This resulted in solution being started as a web project that didn't run inside the Azure emulator. Since CloudConfigurationManager.GetSetting tries to get setting by contacting Azure (or Azure emulator in this case), and it is not running, it returns null.

The solution was to change the StartUp project to the Azure project by right-clicking it and selecting Set as StartUp Project. After this, your web role will start running under Azure emulator and everything will work correctly..

like image 84
Ivan Ferić Avatar answered Oct 04 '22 23:10

Ivan Ferić