weston weston - 1 year ago 296
C# Question

CloudConfigurationManager.GetSetting returning null

Following instructions here I have:

var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");

, here is my app.config:

<?xml version="1.0" encoding="utf-8"?>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<add name="StorageConnectionString"
connectionString="DefaultEndpointsProtocol=https;AccountName=storage;AccountKey=key" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="" newVersion="" />

Answer Source

Well this works, even if the comment doesn't fit, because I do have a ref to CloudConfigManager:

If you are creating an application with no reference to Microsoft.WindowsAzure.CloudConfigurationManager, and your connection string is located in the web.config or app.config as show above, then you can use ConfigurationManager to retrieve the connection string. You will need to add a reference to System.Configuration.dll to your project and add another namespace declaration for it:

using System.Configuration;

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download