生产中的Azure SDK 2.2:无法加载文件或程序集"msshrtmi"或其依赖项之一.该系统找不到指定的文件

Nat*_*nSr 15 .net c# azure

我已经在StackOverflow和其他站点上的其他几个线程上读到了这个问题.其他解决方案都没有解决我的问题,而且大多数已经过时,引用了旧版本的Azure SDK.

我有一个典型的Azure网站角色部署到Azure,用于Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener记录跟踪消息.当发生跟踪时,看起来好像DiagnosticMonitorTraceListener正在使用RoleEnvironment类,而后者又试图加载明显不存在的类msshrtmi.dll.以下是在Azure中记录到文件系统的堆栈跟踪的一部分:

[FileNotFoundException: Could not load file or assembly 'msshrtmi, Version=2.2.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() +747

[TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception.]
   Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable() +0
   Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.GetDefaultStartupInfoForCurrentRoleInstance() +23
   Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener..ctor() +34

[ConfigurationErrorsException: Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.]
   System.Diagnostics.TraceUtils.GetRuntimeObject(String className, Type baseType, String initializeData) +9004943
   System.Diagnostics.TypedElement.BaseGetRuntimeObject() +110
   System.Diagnostics.ListenerElement.GetRuntimeObject() +989
   System.Diagnostics.ListenerElementsCollection.GetRuntimeObject() +252
   System.Diagnostics.TraceInternal.get_Listeners() +331
   System.Diagnostics.TraceInternal.WriteLine(String message) +161
   Microsoft.WindowsAzure.AzureApplicationSettings..ctor() +437
   Microsoft.WindowsAzure.CloudConfigurationManager.get_AppSettings() +137
   Microsoft.WindowsAzure.CloudConfigurationManager.GetSetting(String name) +27
   TankSoft.EverMarket.EverMarketPrereleaseRole.Endpoints.Api.Notify..ctor() +40
   lambda_method(Closure , Object[] ) +60
   Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +315
Run Code Online (Sandbox Code Playgroud)

各种线程已经提到我需要如何从我的bin文件夹中清除这个DLL,但是首先没有复制DLL.我怀疑这与我在Azure SDK 2.2下运行而不是1.x有关.我意识到我可以直接引用DLL,但我觉得我不应该这样做,以便将一个非常正常的项目部署到Azure.为什么Microsoft不会自动检测到我的项目需要此文件并为我部署正确的文件?这令人抓狂.

我还要说,我发布的项目不是Cloud Service,而是一个常规的Azure网站项目.

运行Azure SDK 2.x的任何人都设法解决了这个问题吗?您遵循的具体步骤是什么?

Nat*_*nSr 6

This feels like a hack but it was the only way I could think of to solve this issue.

  1. Open Configuration Manager for the solution
  2. Select the Debug solution configuration
  3. Create a new solution platform for x64
  4. For each web role and worker role project, set the platform to x64
  5. Remove the Any CPU solution platform
  6. Make the same changes to the Release configuration
  7. Add a reference to C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.2\bin\runtimes\base\x64\msshrtmi.dll
  8. Set Copy Local on the new reference to True

配置管理器

EDIT: I ended up removing the code that was checking RoleEnvironment; instead, I'm relying on Web.config/App.config transforms to modify behavior at runtime. This removes the dependency on msshrtmi.dll.