Joseph Anderson
Joseph Anderson

Reputation: 4144

Could not load file or assembly 'msshrtmi, The system cannot find the file specified

I am trying to downgrade a Windows Azure site from the cloud to a website. I am receiving this error:

Could not load file or assembly 'msshrtmi, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

[FileNotFoundException: Could not load file or assembly 'msshrtmi, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment() +0 Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor() +546

[TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.]
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(String configurationSettingName) +0
AzureInit.AzureHelper_GetApplicationSettings(String key) +28

[HttpException (0x80004005): The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9859725
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Because I am not in the cloud, do I need this assembly? How do I tell the website not to look for it? I have added these references to my project:

Microsoft.WindowsAzure.CloudDrive Microsoft.WindowsAzure.Diagnostics Microsoft.WindowsAzure.ServiceRuntime Microsoft.WindowsAzure.StorageClient

In my WorkerRole.cs class, here is my code:

/// <summary>
/// Reads settings from service configuration file. 
/// </summary>
/// <param name="key">Setting key.</param>    
string AzureHelper_GetApplicationSettings(string key)
{
    try
    {
        return RoleEnvironment.GetConfigurationSettingValue(key);
    }
    catch
    {
        // Setting key was not found
        return null;
    }
}

Upvotes: 3

Views: 3206

Answers (1)

Sandrino Di Mattia
Sandrino Di Mattia

Reputation: 24895

Remove these references (and all the code that comes with them):

  • Microsoft.WindowsAzure.CloudDrive
  • Microsoft.WindowsAzure.Diagnostics
  • Microsoft.WindowsAzure.ServiceRuntime

Most features of these assemblies are only meant to be used in Cloud Services (Web/Worker Roles).

Now the error you're seeing seems to be related to reading the configuration:

Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(String configurationSettingName) +0 
AzureInit.AzureHelper_GetApplicationSettings(String key) +28

Consider changing the code in your AzureHelper_GetApplicationSettings to use the Microsoft.WindowsAzure.ConfigurationManager NuGet package. This allows you to automatically switch between the ServiceConfiguration.cscfg and the Web.config (AppSettings). If RoleEnvironment.IsAvailable (= Cloud Service), it will read from the ServiceConfiguration.cscfg. If not (= Web Site / Virtual Machines / On-Premises), it will read from the AppSettings. But if you deploy to Web Sites you'll need to add the settings that used to be in your ServiceConfiguration.cscfg to the appSettings in your web.config

Upvotes: 5

Related Questions