3

我正在尝试将 Windows Azure 站点从云降级为网站。我收到此错误:

无法加载文件或程序集 'msshrtmi, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一。该系统找不到指定的文件。

[FileNotFoundException: 无法加载文件或程序集 'msshrtmi, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一。系统找不到指定的文件。]
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment() +0 Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor() +546

[TypeInitializationException:'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 的类型初始化程序引发异常。]
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(String configurationSettingName) +0
AzureInit.AzureHelper_GetApplicationSettings(String key) +28

[HttpException (0x80004005): 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 的类型初始化程序引发异常。]
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
章 系统.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)+296

[HttpException (0x80004005): 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' 的类型初始化程序引发异常。] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873912
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest WR,HttpContext 上下文)+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;
    }
}
4

1 回答 1

5

删除这些引用(以及它们附带的所有代码):

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

这些程序集的大多数功能仅用于云服务(Web/Worker 角色)。

现在您看到的错误似乎与读取配置有关:

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 读取。但是,如果您部署到网站,则需要将以前在 ServiceConfiguration.cscfg 中的设置添加到 web.config 中的 appSettings

于 2012-12-18T18:52:47.587 回答