【发布时间】:2016-09-21 09:27:18
【问题描述】:
我已将 .NET WebAPI 应用程序(针对 .NET 4.5.2 编译并在本地运行)部署到 Azure 应用程序服务中。
那里抛出的错误是
无法加载文件或程序集“System.Web.Mvc, Version=4.0.40804.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。
我检查了 App 服务的 bin 目录中的 System.Web.Mvc.dll 的大小为 505504 字节 - 与我的本地 System.Web.Mvc.dll 的大小完全相同,即 4.0 版。 40804.0,于 2014 年 9 月 25 日更改,并且在本地工作没有问题。我能说的唯一区别是我在本地安装了 .NET 4.5.2,而不是像 Azure 那样的 4.6.1。
我的 Web.config 中的条目是
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="4.0.40804.0" />
</dependentAssembly>
但我已经尝试过
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
这也不起作用。
我必须如何编辑该条目才能让我的应用程序找到 System.Web.Mvc.dll?
作为参考,完整的错误信息是:
“/”应用程序中的服务器错误。
无法加载文件或程序集“System.Web.Mvc”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.IO.FileLoadException:无法加载文件或程序集“System.Web.Mvc”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)
来源错误:
在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。
程序集加载跟踪:以下信息有助于确定无法加载程序集“System.Web.Mvc”的原因。
警告:程序集绑定日志记录已关闭。 要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) 设置为 1。 注意:有一些与程序集绑定失败日志相关的性能损失。 要关闭此功能,请删除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。
堆栈跟踪:
[FileLoadException:无法加载文件或程序集“System.Web.Mvc”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (HRESULT 异常:0x80131040)]
[FileLoadException:无法加载文件或程序集“System.Web.Mvc,版本=4.0.40804.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040)] System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +36 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,证据 assemblySecurity,RuntimeAssembly reqAssembly,StackCrawlMark 和 stackMark,IntPtr pPrivHostBinder,布尔 throwOnFileNotFound,布尔 forIntrospection,布尔 suppressSecurityChecks)+152 System.Reflection.RuntimeAssembly.InternalLoad(字符串 assemblyString,证据 assemblySecurity,StackCrawlMark 和 stackMark,IntPtr pPrivHostBinder,Boolean forIntrospection)+77 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +21 System.Reflection.Assembly.Load(String assemblyString) +28 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException:无法加载文件或程序集“System.Web.Mvc,版本=4.0.40804.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040)] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +217 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170 System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +92 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +290 System.Web.Compilation.BuildManager.ExecutePreAppStart() +157 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531
[HttpException (0x80004005): 无法加载文件或程序集“System.Web.Mvc,版本=4.0.40804.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自 HRESULT 的异常:0x80131040)] System.Web.HttpRuntime.FirstRequestInit(HttpContext 上下文) +9947380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.6.1055.0
【问题讨论】:
-
@MusicLovingIndianGirl 它正在寻找版本 4.0.40804.0,并且与我的 WebAPI DLL 位于同一目录中的文件的版本为 4.0.40804.0。所以那边的答案没有帮助。此外,我无法在 Azure 应用服务上“使用 Windows 文件搜索搜索 [我的] 硬盘驱动器以查找 [我的] 程序集”。
标签: c# asp.net asp.net-mvc azure .net-assembly