{"id":673,"date":"2011-03-05T14:57:21","date_gmt":"2011-03-05T14:57:21","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/cesardelatorre\/2011\/03\/05\/how-to-solve-setconfigurationsettingpublisher-needs-to-be-called-before-fromconfigurationsetting-can-be-used-after-moving-to-windows-azure-sdk-1-3\/"},"modified":"2011-03-05T14:57:21","modified_gmt":"2011-03-05T14:57:21","slug":"how-to-solve-setconfigurationsettingpublisher-needs-to-be-called-before-fromconfigurationsetting-can-be-used-after-moving-to-windows-azure-sdk-1-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/how-to-solve-setconfigurationsettingpublisher-needs-to-be-called-before-fromconfigurationsetting-can-be-used-after-moving-to-windows-azure-sdk-1-3\/","title":{"rendered":"How to solve \u201cSetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used\u201d After Moving to Windows Azure SDK 1.3"},"content":{"rendered":"<p>&#160;<\/p>\n<p>A quick reminder:<\/p>\n<p>After Windows Azure SDK 1.3, we now use full IIS instead HWC (Hosted Web Core). Using IIS we can have several WebSites per WebRole, so now the internal architecture and processes are different, this is why we have to change the we we use the API regarding Windows Azure configuration settings.<\/p>\n<p>Basically, in case you\u2019re using ASP.NET, we need to add the following code to our Global.asax<\/p>\n<p>Global.asax in ASP.NET<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected void Application_Start()   <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/(CDLTLL) Configuration for Windows Azure settings    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CloudStorageAccount.SetConfigurationSettingPublisher(    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (configName, configSettingPublisher) =&gt;    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var connectionString =    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; RoleEnvironment.GetConfigurationSettingValue(configName);    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; configSettingPublisher(connectionString);    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; );    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/p>\n<p>Here is an interesting post regarding how to solve this issue, for detailed information:<\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/windowsazure\/archive\/2010\/12\/08\/how-to-resolve-setconfigurationsettingpublisher-needs-to-be-called-before-fromconfigurationsetting-can-be-used-after-moving-to-windows-azure-sdk-1-3.aspx\">http:\/\/blogs.msdn.com\/b\/windowsazure\/archive\/2010\/12\/08\/how-to-resolve-setconfigurationsettingpublisher-needs-to-be-called-before-fromconfigurationsetting-can-be-used-after-moving-to-windows-azure-sdk-1-3.aspx<\/a><\/p>\n<p>Then, if you want to get a connection string (like ADO.NET or EF connString) from WA-Conf-Settings or from a regular Web.config, depending on what environment you are running your app, you can check if you are running on Windows Azure using \u2018<strong>RoleEnvironment.IsAvailable<\/strong>\u2019, so doing the following can be very useful:<\/p>\n<p>CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =&gt;   <br \/>{    <br \/>&#160;&#160;&#160; string connectionString; <\/p>\n<p>&#160;&#160;&#160; if (RoleEnvironment.IsAvailable)   <br \/>&#160;&#160;&#160; {    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);    <br \/>&#160;&#160;&#160; }    <br \/>&#160;&#160;&#160; else    <br \/>&#160;&#160;&#160; {    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connectionString = ConfigurationManager.AppSettings[configName];    <br \/>&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160; configSetter(connectionString);   <br \/>});&#160;&#160; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#160; A quick reminder: After Windows Azure SDK 1.3, we now use full IIS instead HWC (Hosted Web Core). Using IIS we can have several WebSites per WebRole, so now the internal architecture and processes are different, this is why we have to change the we we use the API regarding Windows Azure configuration settings. [&hellip;]<\/p>\n","protected":false},"author":362,"featured_media":12806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cesardelatorre"],"acf":[],"blog_post_summary":"<p>&#160; A quick reminder: After Windows Azure SDK 1.3, we now use full IIS instead HWC (Hosted Web Core). Using IIS we can have several WebSites per WebRole, so now the internal architecture and processes are different, this is why we have to change the we we use the API regarding Windows Azure configuration settings. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/comments?post=673"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/posts\/673\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media\/12806"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/media?parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/categories?post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cesardelatorre\/wp-json\/wp\/v2\/tags?post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}