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:
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?
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?
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'".
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.
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:
svc = CreateDataServiceContext(); DataServiceQuery
> queryObj = svc.CreateQuery<RoleRow
query = (from
role.PartitionKey == SecUtility
> userRows = query.Execute().ToList();
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,
privatestaticobject gate = newobject();
privatestaticbool initialized = false;
// insert role initialization here
initialized = true;
"Could not load file or assembly 'Microsoft.WindowsAzure.StorageClient, Version=18.104.22.168, 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.
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 22.214.171.124 so you may need to update the reference in your project.
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.)
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?
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.