2012-12-18 34 views
3

我試圖將Windows Azure站點從雲降級到網站。我收到此錯誤:無法加載文件或程序集「msshrtmi,系統找不到指定的文件

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

因爲我不在雲中,是否需要此程序集?我如何告訴網站不要查找它?我已經加入到我的項目,這些引用:

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

在我WorkerRole.cs類,這裏是我的代碼:

/// <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; 
    } 
} 

回答

5

刪除這些引用(和所有的代碼,來與他們):

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

這些組件的大部分功能僅意味着雲服務(Web /工作者角色)使用。

現在你看到的錯誤似乎與讀取配置:

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

考慮您的AzureHelper_GetApplicationSettings使用Microsoft.WindowsAzure.ConfigurationManager NuGet包更改代碼。這使您可以在ServiceConfiguration.cscfg和Web.config(AppSettings)之間自動切換。如果RoleEnvironment.IsAvailable(= Cloud Service),它將從ServiceConfiguration.cscfg中讀取。如果沒有(=網站/虛擬機/本地),它將從AppSettings中讀取。但是,如果您部署到Web站點,則需要將以前在ServiceConfiguration.cscfg中的設置添加到web.config中的appSettings

相關問題