We are currently moving some instances of our application to Azure, but will still maintain backwards compatibility with existing instances which are not Azure hosted.
Is there a good way to detect the environment without installing the SDK on the non-Azure production server?
I've tried using:
if (RoleEnvironment.IsAvailable)
from Microsoft.WindowsAzure.ServiceRuntime, and it works perfectly locally, and in Azure. However, I need to set the Microsoft.WindowsAzure.ServiceRuntime.dll to CopyLocal, and even then I get:
Could not load file or assembly 'msshrtmi, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies
There doesn't seem to be a NuGet package, and I don't want to manually copy the msshrtmi dll about.
Perhaps there's a way of detecting without the dependency on Microsoft.WindowsAzure.ServiceRuntime?
In this quickstart, you'll learn how to create and deploy your first ASP.NET web app to Azure App Service. App Service supports various versions of . NET apps, and provides a highly scalable, self-patching web hosting service. ASP.NET web apps are cross-platform and can be hosted on Linux or Windows.
It uses the standard OAuth 2.0 client credentials grant. In the Azure portal, select Active Directory > App registrations > New registration.
In Azure App Service, certain settings are available to the deployment or runtime environment as environment variables. Some of these settings can be customized when you set them manually as app settings. This reference shows the variables you can use or customize.
To access App Service diagnostics, navigate to your App Service web app or App Service Environment in the Azure portal. In the left navigation, click on Diagnose and solve problems.
Unfortunately the easiest way to resolve this is to copy the msshrtmi.dll file from:
C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\{version}\bin\runtimes\base\x64
I know it's not very nice copying DLLs around, but this is the only one you'll need to prevent the error, and its tied to the SDK version you're using, so won't change until you update the SDK.
A viable alternative would be to add a config value in appSettings
and apply a config transform when you build the application for Azure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With