AZURE

Windows Azure for Developers Task 12: SetConfigurationSettingPublisher needs to be called before FromConfiguration Setting can be used error

Have you spent your hours getting rid of below exception ?

clip_image001

I spent. So in this blog post, I am trying to save your time.

Very first let us understand why this error occurs?

Azure application runs in Full IIS model from SDK 1.3 onwards.

In simple English we can say that from SDK 1.3 onwards WebRole.cs and Web Application codes run in different application domain. So if we write or we do have code for Set Configuration setting in WebRole.cs then we are going to get above exception.

How to solve?

1. Make sure you have Diagnostic connection string in settings of Web Role.

clip_image003

2. See if in your Web Role project Global.asax file exist. If it does not exist then right click on the Web Role project and add one.

3. Open Global.asax.cs file and in Application_Strat() add the below code

clip_image005

Bottom line is to get rid of below exception, you need to copy below code in Application_Strat() .

Code to copy


CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) =>
{
var connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
configSettingPublisher(connectionString);
}
);

I hope this post may have saved your some time.

About Dhananjay Kumar

Dhananjay Kumar is Developer, Blogger , Speaker, Learner , Mindcracker & Microsoft MVP.

Discussion

4 Responses to “Windows Azure for Developers Task 12: SetConfigurationSettingPublisher needs to be called before FromConfiguration Setting can be used error”

  1. You don’t need to bother with SetConfigurationSettingPublisher() if you use the following instead:

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(“DataConnectionString”));

    Posted by Neil Mackenzie | April 23, 2011, 11:30 am
  2. Hi Neil ,

    Thanks for sharing. I just tried your solution and it is working fine.

    Thanks again for sharing.

    var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(“DataConnectionString”));

    I will make one more blog post on the same such that community would get benifited

    Posted by Dhananjay Kumar | April 23, 2011, 11:37 am

Trackbacks/Pingbacks

  1. Pingback: Windows Azure for Developers Task 13: SetConfigurationSettingPublisher needs to be called before FromConfiguration Setting can be used error [Other Solution] « DEBUG MODE…… - April 23, 2011

  2. Pingback: Monthly Report April 2011: Total Posts 21 « debug mode…… - December 4, 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,380 other followers

Tweets

Categories

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my current or previous employer's view in anyway. © Copyright 2012