I'm currently testing my ASP.NET site in three ways:
- Debugging locally
- Deploying as an azure website
- Testing in the Azure emulator (soon to deploy with roles)
I have an if/else which is trying to detect if the role environment is available. It works fine locally, but blows up when run in the Azure website environment with:
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.5.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) File name: 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
My code is as follows:
if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")) && Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.IsAvailable)
{
//drop item on the queue for it to be picked up by the worker role
}
else
{
//Process here
}
I have it short circuit such that the RoleEnvironment code will never run when on a website. I've attached a debugger to verify that the first part of the statement returns false. But the exception happens whenever I first jump into the method containing that call.
Does anyone have any suggestions to allow my code to function correctly, regardless of if it's running with roles available, in an azure website, or locally? I haven't done anything to customize the website after it's deployed.
Edit: based on this thread: Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=1.8.0.0 when deployed to the cloud
The assemblies Microsoft.WindowsAzure.Diagnostics and Microsoft.WindowsAzure.ServiceRuntime cannot be used in a Web Site.
If that's the case, is there any way to help automate this so that I don't have to maintain two separate versions of my code?
Edit 2: I'm considering doing conditional compilation around this. Not fully automatic, but might be the best possible solution.