Jonas Stensved
Jonas Stensved

Reputation: 15276

CloudConfigurationManager.GetSetting returns empty string in production?

I've just upgraded my project to Azure Tools 1.8 (October 2012 SDK) and I'm running into a strange issue;

In my WorkerRole my calls to CloudConfigurationManager.GetSetting returns null (can be empty string, hard to tell from log file). In other words; I can't fetch settings from the RoleEnvironment.

Info:

Any clues?

Update:

Calling code (method Run() in WorkerRole)

public override void Run(){

   // Fetch connectionstring
   var connectionString = CloudConfigurationManager.GetSetting("ConnectionString");

   // connectionString is null here?

  [...]

}

The setting is visible in the portal so it is certainly deployed.

Upvotes: 4

Views: 3651

Answers (4)

acarlon
acarlon

Reputation: 17264

I got this after upgrading Azure SDK from 2.0 to 2.2. I was able to fix by:

  1. Right-Clicking Azure project and selecting Properties. Update Azure SDK as per the Application tab. Thanks to rattrick1's answer.
  2. Right click to Manage NuGet Packages. On the left click Updates and update WindowsAzure.ConfigurationManager.

Upvotes: 1

Scott Scowden
Scott Scowden

Reputation: 1195

I had the same problem. I had updated the project to use Azure SDK 2.0. I updated NuGet packages for my web and worker roles, but the Azure project in Visual Studio was still on the old version.

To fix this, Right-Click on your Azure project and select Properties. Under the Application tab, you'll see a button to Update your Azure SDK.

Upvotes: 1

Jonas Stensved
Jonas Stensved

Reputation: 15276

I've fixed it, the following steps solved it:

  • One of the projects referenced Microsoft.WindowsAzure.Configuration version 1.7.0.0. Changed this (strange if this is the cause though since the dll in the output where the correct version. Maybe it was loaded from GAC at runtime?)
  • Removed assembly binding redirects for Microsoft.WindowsAzure.Configuration
  • Upgraded the osFamily from 1 to 2 (Windows 2008 SP2 -> Windows 2008 R2)

Some steps are probably unnecessary but I'm not sure which of them :-)

Upvotes: 4

freakyroach
freakyroach

Reputation: 460

How about using RoleEnvironment.GetConfigurationSettingValue("ConnectionString") instead; assuming you are trying to get a value from service configuration file (cscfg) ?

Upvotes: 1

Related Questions