部署到云时无法加载文件或程序集'Microsoft.WindowsAzure.ServiceRuntime,Version = 1.8.0.0

w.b*_*ian 16 azure azure-web-roles

我有一个在本地运行良好的MVC 4应用程序但在部署到Azure时失败并显示此消息:

[FileNotFoundException: Could not load file or assembly Microsoft.WindowsAzure.ServiceRuntime, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.] Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitor.GetDefaultStartupInfoForCurrentRoleInstance() +0 Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener..ctor() +40

我已经确定我引用了Microsoft.WindowsAzure.ServiceRuntime 1.8版并将其设置为复制本地.

San*_*tia 19

因此,从您的屏幕截图中看起来您创建了一个Web站点(不是Cloud Service或Web角色).程序集Microsoft.WindowsAzure.DiagnosticsMicrosoft.WindowsAzure.ServiceRuntime不能在网站中使用.

如果要创建Web角色,请打开Visual Studio>文件>新建项目>云> Windows Azure云服务>添加MVC Web角色>确定.完成后,右键单击Azure项目并选择" 发布".这将允许您创建一个包含Web角色的新Cloud Service.如果您像这样创建项目,您将能够使用Microsoft.WindowsAzure.DiagnosticsMicrosoft.WindowsAzure.ServiceRuntime程序集.


vip*_*naz 12

检查项目中的引用,并确保所有Azure引用都标记为Copy Local = True.此外,由于该应用程序正在寻找运行时版本1.8,您显然使用SDK 1.8中的至少一个程序集 - C:\ Program Files\Microsoft SDKs\Windows Azure.NET SDK\2012-10\ref ... 注意:2012- 10.然后检查使用的参考版本:

  • 诊断:1.8.0.0
  • 运行时间:1.8.0.0

通常会发生此程序集不匹配,因为您引用了不同的SDK版本和/或您的引用未标记为copy local = true.

至于Azure分类,有网站(在网站下的门户网站上),云服务可以有WebRoles(网站,wcf服务)或WorkerRoles(后端处理).

对于CloudServices,OS系列和GuestOS在"ServiceConfiguration"元素的ServiceConfiguration.cscfg文件中指定:

<ServiceConfiguration serviceName="MyWebRole" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="3" osVersion="*" schemaVersion="2012-10.1.8">
Run Code Online (Sandbox Code Playgroud)

osFamily 2 = Server 2008R2和3 = Server 2012.osVersion指定了GuestOS,对于最新版本,几乎总是"*".

如果所有其他方法都失败了,并且bin中正确的DLL被删除,请尝试在web.config中添加程序集绑定重定向:

<dependentAssembly>
  <assemblyIdentity name="Microsoft.WindowsAzure.ServiceRuntime" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-1.8.0.0" newVersion="1.8.0.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)