无法加载文件或程序集"msshrtmi"或其依赖项之一(Azure表存储访问)

Wil*_*son 49 .net c# httpmodule azure azure-storage

我有一个HTTPModule,用于重定向数据中心的网站和Azure平台上运行的网站之间的流量.此HTTPModule从Azure表存储中检索其重定向规则.

重定向在我的本地开发计算机上以及在Azure上运行时都能正常工作.但是,当我将模块部署到我的数据中心服务器(IIS 7,WS 2008 R2标准64位,.NET 4.0,ASP.NET 4.0)时,我收到以下错误

Parser Error Message: Could not load file or assembly 'msshrtmi' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Line 124:                <add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 125:                <add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Line 126:                <add assembly="*" />
Line 127:            </assemblies>
Line 128:            <buildProviders>

Source File: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config    Line: 126 
Run Code Online (Sandbox Code Playgroud)

"msshrtmi.dll"实际存在于我的部署bin目录中.

如果我删除此dll数据中心站点工作正常,但HTTPModule无法从表存储加载其配置数据,而是抛出以下错误

---> System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'msshrtmi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment()
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable()
Run Code Online (Sandbox Code Playgroud)

此外,我手动包含"Microsoft.WindowsAzure.ServiceRuntime.dll"作为部署的一部分,以确保它在数据中心服务器上可用.

Jer*_*Gee 30

似乎Azure项目对该特定文件非常敏感.来自:http://social.msdn.microsoft.com/Forums/en-US/windowsazuretroubleshooting/thread/0fac1f05-eb55-432f-80ac-6f15cde5b14b/

当您为Web角色项目进行重建时,我可以请您检查bin文件夹中是否有msshrtmi.dll文件?如果是,那么请使用Dependency Walker检查它是64位还是32位.如果是32位,请尝试以下任一选项以防止将此dll文件输出到bin文件夹.

  1. 将Web角色项目定位到x64并重新创建azure服务项目.此选项已通过http://social.msdn.microsoft.com/Forums/en/windowsazure/thread/286cecf6-1423-4ef3-93f9-0eb8a67d8192确认 .(编辑:现在是12月12日的死链接.)

  2. 使用记事本打开网站项目文件,并从所有配置属性组中删除PlatformTarget元素.此选项引自 http://tomkrueger.wordpress.com/2010/07/27/azure-deployment-issue-after-upgrading-to-visual-studio-2010-and-net-4-0/.

  3. 编写Post-build事件命令以在成功执行构建操作时删除msshrtmi.dll.为此,请右键单击Web角色项目,然后选择"属性".选择Build Events选项卡,在"Post-build event命令行"文本框中输入以下命令:

cd $(TargetDir) del msshrtmi.dll

这一切都表明您需要检查是否已在目标环境中构建了正确的部署配置.确保已将x64作为目标部署到数据中心服务器.


Gae*_*eur 19

这解决了我的问题.在VS2013的Developer Command Prompt中运行此命令.

gacutil /i "C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.0\bin\runtimes\base\x64\msshrtmi.dll"
gacutil /i "C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.0\bin\runtimes\base\x86\msshrtmi.dll"
Run Code Online (Sandbox Code Playgroud)

这将在全局程序集缓存中注册运行时文件,以便所有.NET应用程序都可以访问它.


Rob*_*per 18

我刚刚遇到这个帖子,因为我遇到了同样的问题 - 不幸的是,上述步骤都没有对我有用.

经过一段时间的搔痒和捣乱 - 我找到了解决方案,这非常简单/令人尴尬.

我在这里写博客.

  • 右键单击Azure项目(具有蓝色地球的项目).
  • 单击"应用程序"选项卡.
  • 请注意,有一个按钮告诉您安装了较新的SDK? 点击它!

因此,事实证明,对一些文件进行了一些细微的更改,这些更改会产生重大影响:

  • .csdef文件 - ' schemaVersion'已更新.
  • .ccproj - ' ProductVersion'和' CloudExtensionsDir'已更新.
  • .csproj - 您将更新Azure SDK引用(ServiceRuntime,Diagnostics等)

我认为杀手是' CloudExtensionsDir'对我来说,这改变了:

<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">
  $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\1.7\
</CloudExtensionsDir>
Run Code Online (Sandbox Code Playgroud)

至:

<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">
  $(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\1.8\
</CloudExtensionsDir>
Run Code Online (Sandbox Code Playgroud)

部署到Azure,立即工作.

希望这可以帮助!

PS:我应该补充一点,我不需要卸载任何旧的SDK或任何东西,或者使用'Platform Targets'搞乱.只是改变这个工作正常.

  • 请注意,在右键单击项目以检查更新之前,请先下载最新的SDK!谢谢Rob.+1 (2认同)