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.

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”));

  2. Dhananjay Kumar

    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

  3. […] In my previous post, I suggested solution of above exception , and I got a comment from one of my reader that there is an easier way to solve above exception as well. So I decided to make a post on the other way of solution as well. […]

  4. […] Windows Azure for Developers Task 12: SetConfigurationSettingPublisher needs to be called before Fro… […]

Leave a comment

Create a website or blog at WordPress.com