none
Issues with v1.3 SDK

    Question

  • Hi all,

    I installed the new SDK and I'm having two issues with an app that was working perfectly on v1.2.  This app has a worker role and a web role.  The Azure project in my solution is set as my startup project.

    In my web role, I'm accessing blob storage.  When I do this:

     

    CloudStorageAccount cloudStorageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString"
    );
    

     

    I get an exception: "SetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used".

    However, SetConfigurationSettingPublisher has already been called in the OnStart event of my web role:

     

    CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
          {
                    configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
    
            RoleEnvironment.Changed += (sender, arg) =>
            {
              if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()
                .Any((change) => (change.ConfigurationSettingName == configName)))
              {
                if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))
                {
                  RoleEnvironment.RequestRecycle();
                }
              }
            };
          });

    Again, this code worked properly before the update to 1.3

     

    Secondly, when I debug the app in Visual Studio 2010 (pressing F5), it starts the app and launches TWO browser windows, instead of one.  Both windows have the same URL: the starting URL of my project. This isn't necessarily a big deal, but I'm wondering if the two issues are related, and are side-effects of a broader problem?

    Tuesday, November 30, 2010 4:02 PM

Answers

  • When you run with SDK 1.3 the web role is upgraded to full IIS. This means that the web site executes in another process (w3wp.exe) and you need to call SetConfigurationSettingPublisher in that process. In other words, move the call from OnStart to Application_Start.

    Regarding your second problem, duplicate browser windows, do you have multiple input endpoints defined for your site, for example, HTTP and HTTPS?

    • Proposed as answer by Anton StaykovMVP Tuesday, November 30, 2010 8:46 PM
    • Edited by Fernando Tubio Wednesday, December 01, 2010 3:33 AM Added SDK version
    • Marked as answer by Mog Liang Wednesday, December 08, 2010 9:34 AM
    Tuesday, November 30, 2010 4:21 PM

All replies

  • When you run with SDK 1.3 the web role is upgraded to full IIS. This means that the web site executes in another process (w3wp.exe) and you need to call SetConfigurationSettingPublisher in that process. In other words, move the call from OnStart to Application_Start.

    Regarding your second problem, duplicate browser windows, do you have multiple input endpoints defined for your site, for example, HTTP and HTTPS?

    • Proposed as answer by Anton StaykovMVP Tuesday, November 30, 2010 8:46 PM
    • Edited by Fernando Tubio Wednesday, December 01, 2010 3:33 AM Added SDK version
    • Marked as answer by Mog Liang Wednesday, December 08, 2010 9:34 AM
    Tuesday, November 30, 2010 4:21 PM
  • agree with @fernado - 

    on the second prob, right click on your web role - turn off the HTTPS or HTTP end points depending on what you need if you don't want both opening.

    Tuesday, November 30, 2010 5:36 PM
  • Regarding the SetConfigurationSettingPublisher issue, you're exactly right.  Thanks!

    I'm still getting two browser windows, though, and I have only one endpoint defined - HTTP.

    Tuesday, November 30, 2010 11:46 PM
  • The same as plunkg, I have 2 browser windows too. 

    It is not big issue,but I would be more than happy to see it fixed.

    Tuesday, November 30, 2010 11:53 PM
  • Can you share your servicedefinition.csdef file?
    Wednesday, December 01, 2010 3:33 AM
  • Here's my CSDEF file:

     

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="AA_Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
     <WebRole name="UIRole" enableNativeCodeExecution="true">
      <Sites>
       <Site name="Web">
        <Bindings>
         <Binding name="HttpIn" endpointName="HttpIn" />
        </Bindings>
       </Site>
      </Sites>
      <LocalStorage name="ShortTermStorage-UI" sizeInMB="50" />
      <ConfigurationSettings>
       <Setting name="DiagnosticsConnectionString" />
       <Setting name="DataConnectionString" />
       <Setting name="ActivityID" />
      </ConfigurationSettings>
      <Endpoints>
       <InputEndpoint name="HttpIn" protocol="http" port="80" />
      </Endpoints>
     </WebRole>
     <WorkerRole name="BackgroundAgent" enableNativeCodeExecution="true">
      <LocalStorage name="ShortTermStorage-BG" sizeInMB="50" />
      <ConfigurationSettings>
       <Setting name="DiagnosticsConnectionString" />
       <Setting name="DataConnectionString" />
       <Setting name="AccountsConnectionString" />
       <Setting name="MessageFetchInterval" />
       <Setting name="ActivityID" />
      </ConfigurationSettings>
     </WorkerRole>
    </ServiceDefinition>
    

    Wednesday, December 01, 2010 3:46 AM
  • Sorry. Nothing stands out.

    One last suggestion, try renaming the [solutionname].suo (hidden) and the [projectname].csproj.user files and then loading the project again before you run it.

    Wednesday, December 01, 2010 4:48 AM
  • This fixed my problem. delete everything and sync up my code (source code only) again. I did not see two browser pop up.

     

    I used to have 2 http end points. I removed one, but some .suo or .user file still remember the old settings.

     

    Plunkg, how about you?

    Wednesday, December 01, 2010 4:58 AM
  • Worked for me thank!
    Wednesday, December 01, 2010 6:45 PM
  • I have also issiue with v1.3 SKD. The Phluffyfotos example does not work. More specifically Role provider is not resolved from web config. I get the following error: "The Role Manager feature has not been enabled.", because of the following exception "'System.Web.Security.Roles.ApplicationName' threw an exception of type 'System.Configuration.Provider.ProviderException'".

    What is wrong?

    Can someone test this example and see what is the problem? http://phluffyfotos.codeplex.com/

    I have also post a question on SO: http://stackoverflow.com/questions/4326096/phluffyfotos-does-not-work-on-azure-sdk-1-3


    Thursday, December 02, 2010 10:50 AM
  • Besides SetConfigurationSettingPublisher, you also need to move the code that creates the roles to the web application. Keep in mind that OnStart executes in a different process from the web site and that the configuration settings in web.config, which include the membership and roleManager sections, apply to the web site only.

    Note that if you move the code that uses the role manager to Application_Start, I suspect that you may hit another (unrelated) problem, but give it a try.

    Thursday, December 02, 2010 1:35 PM
  • Thanks Fernando, but here are another problem as you suspect it. The "GetAllRoles()" are now called, but problem arise when the call to azure storage is made. I get exception "Response is not available in this contex" when the "ToList()" is called. Here is the code:

    DataServiceContext
     svc = CreateDataServiceContext();
    DataServiceQuery <RoleRow > queryObj = svc.CreateQuery<RoleRow >(_tableName);
     var query = (from role in queryObj
     where role.PartitionKey == SecUtility .CombineToKey(_applicationName, string .Empty)
    select role).AsTableServiceQuery();
    IEnumerable <RoleRow > userRows = query.Execute().ToList();
    Thursday, December 02, 2010 3:08 PM
  • Yes. This is a problem that I believe was introduced by .NET 4. I haven't analyzed this in detail, so there may be a better solution,  but a workaround is to use Application_BeginRequest instead and execute the code conditionally so that it is executed one time only. For example,

    private static object gate = new object();
    private static bool initialized = false;
    
    protected void Application_BeginRequest()
    {
      if (initialized)
      {
        return;
      }
    
      lock (gate)
      {
        if (!initialized)
        {
          // insert role initialization here
    
          initialized = true;
        }
      }
    }
    
    
    Thursday, December 02, 2010 3:19 PM
  • I've had several additional errors:

    • "Could not load file or assembly 'Microsoft.WindowsAzure.StorageClient, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
    • "Response is not available in this context", as noted by Peter
    • And once again, "SetConfigurationSettingPublisher needs to be called before FromConfigurationSetting can be used"

    ...and just generally inconsistent and unstable behavior.  Sometimes the app wouldn't run at all because of the first error.  Sometimes it would run but throw one of the other errors when trying to access a blob.  I recycled the Computer Emulator and everything started working properly again. 

    This tells me that the application object is still running but is losing its SetConfigurationSettingPublisher setting.  So I think that putting the initializer in Application_BeginRequest is a better solution, as Fernando shows above.  It's working so far, at least.

    One further note: I have code in my Session_End event that accesses Azure storage - you'll want to put the same initialization check there.

    Thursday, December 02, 2010 4:20 PM
  • Hi plunkg,

    I now realize that my previous reply may be misinterpreted. In the code that I included, for the comment "insert role initialization here", the reference to the term "role" was meant for the initialization of the roleManager (as in AspNetSqlRoleProvider) specifically to work around the "Response is not available in this context" error, and not the initialization of the web role as a whole.  So far, I haven't seen any issues with calling SetConfigurationSettingPublisher in Application_Start, so I don't know what may be causing the application to lose this setting in your case.

    Regarding the StorageClient assembly error, in v1.3 the version is now 1.1.0.0 so you may need to update the reference in your project.

    Thursday, December 02, 2010 6:03 PM
  • @Fernando this is it. Thanks!

    But I wonder, can you please explain why Azure data contex is not available at Application_Start event? I guess that the web role is not started yet and underlying services is not initialized?

    Friday, December 03, 2010 7:57 AM
  • I can't find the details, but as I recall there's some issue with ASP.NET 4 and HTTP web requests made in Application_Start.  (I really can't remember what the exact issue was, but I suspect it's just that, and not something related to Windows Azure.)
    Friday, December 03, 2010 7:44 PM
  • But I wonder, can you please explain why Azure data contex is not available at Application_Start event? I guess that the web role is not started yet and underlying services is not initialized?


    Hi Peter,

    Steve is correct. This problem is not specific to Windows Azure. Actually, what isn't available is a response because Application_Start is a global event and there really isn't a response (or a client to send the response to) associated with this event. 

    Now, the question is why does it need a response object at all? This seems to be a breaking change in .NET 4. If you change the target framework to 3.5, you will probably see that the code works correctly in Application_Start. I've found similar behavior when trying to create containers and blobs in Application_Start, which is probably what the TableStorageRoleProvider is also trying to do (see http://social.msdn.microsoft.com/Forums/en/windowsazuredata/thread/f8b88304-f4fb-4e23-beb8-efd903d32b0a).

     

    Saturday, December 04, 2010 5:47 PM