我在 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
各种线程都提到了我需要如何从 bin 文件夹中清除此 DLL,但该 DLL 一开始就没有被复制。我怀疑这与我在 Azure SDK 2.2 而不是 1.x 下运行有关。我意识到我可以直接引用 DLL,但我觉得我不必这样做才能将一个非常正常的项目部署到 Azure。为什么 Microsoft 没有自动检测我的项目需要此文件并为我部署正确的文件?这太令人抓狂了。
我还要说一下,我正在发布的项目不是云服务,而是一个常规的 Azure 网站项目。
有人运行 Azure SDK 2.x 设法解决此问题吗?您具体执行了哪些步骤?
最佳答案
这感觉像是黑客攻击,但这是我能想到解决这个问题的唯一方法。
- 打开解决方案的配置管理器
- 选择调试解决方案配置
- 创建新的 x64 解决方案平台
- 对于每个 Web 角色和辅助角色项目,将平台设置为 x64
- 删除 Any CPU 解决方案平台
- 对发布配置进行相同的更改
- 添加对
C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.2\bin\runtimes\base\x64\msshrtmi.dll的引用
- 将新引用上的
Copy Local
设置为True
编辑:我最终删除了检查 RoleEnvironment 的代码;相反,我依靠 Web.config/App.config 转换来修改运行时的行为。这消除了对 msshrtmi.dll 的依赖。
关于c# - Azure SDK 2.2 in Production : Could not load file or assembly 'msshrtmi' or one of its dependencies. 系统找不到指定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19649185/