Reputation: 369
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!
Upvotes: 6
Views: 1191
Reputation: 4297
I had the exact same thing happening. It is a versioning problem but it's not easy to see.
If I right clicked on Microsoft.WindowsAzure.Configuration in the References list in VS, it said version 3.0.0.0 for both projects (one worked and one didn't). But...if I opened up the packages.config file for each project, one was actually referencing 3.2.1 (and worked) and one was referencing 3.0.0 (didn't work). I used Nuget to update it to 3.2.1 to match the other and all works fine now.
So annoying!
Upvotes: 0
Reputation: 4763
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..
Upvotes: 1