Visual Studio 的 IIS Express:无法加载文件或程序集

Visual Studio's IIS Express: Could not load file or assembly

我在尝试加载解决方案 (GMap.NET) 时遇到了一些问题,我在构建时遇到了一些问题。不过现在不确定这是否重要。

我在Visual Studio2015年开发了一个小系统,里面也有一个MVC项目。当我启动基本网站时 - 或多或少只是初始 MVC 5 模板 - 通过 Visual Studio 2015 - 使用 IIS Express - 我收到此错误消息:

Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) [There is more]

不知道1.0.0.0版本是哪来的!我引用的版本是 3.0.0.0...

此外 - 如果我发布到我的本地 IIS - 它有效! 我在另外两台计算机上打开了相同的解决方案 - 我可以从 Visual Studio 启动它! 这意味着 - 问题出在我的电脑上 - 而不是我的解决方案......我很确定。

我怀疑机器出了问题。也许在 GAC 或某些配置中,但我不知道在哪里...我正在考虑这样的文件(我不太了解它们):

对于 GAC,似乎没有 System.Web.WebPages.Deployment.dll。由于它可以在 "real" IIS 上运行,因此在 IIS 上也应该没问题。

我还尝试删除 'C:/Users/#user#/AppData/Local/Temp/Temporary ASP.NET Files/vs/'

中的所有文件

这应该缩小到: - 问题一定与 Visual Studio and/or IIS Express - and/or 一些配置文件有关。 - 解决方案中的引用不是问题。 (我用nuget安装了MVC)

外汇。在此文件中,有一个 System.Web.WebPages.Deployment 版本 1.0.0.0 的条目: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config:

<compilation>
  <assemblies>
<!-- <remove assembly="System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add assembly="System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> -->`
...
</compilation>

但我已经尝试取消注释了。没有区别...

因此,如果有人能给我提示在哪里查看...要比较的文件或其他内容,我将不胜感激!

这是我收到的完整消息:

Server Error in '/' Application.

Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\Program Files (x86)\IIS Express\iisexpress.exe --- A detailed error log follows.

=== Pre-bind state information === LOG: DisplayName = System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///C:/Users/#user#/Source/Workspaces/MySystem/MySystem/Frontend.Web/ LOG: Initial PrivatePath = C:\Users#user#\Source\Workspaces\MySystem\MySystem\Frontend.Web\bin

Calling assembly : (Unknown).

LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users#user#\Source\Workspaces\MySystem\MySystem\Frontend.Web**web.config** LOG: Using host configuration file: C:\Users#user#\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/#user#/AppData/Local/Temp/Temporary ASP.NET Files/vs/0c78498f/ece65cb2/System.Web.WebPages.Deployment.DLL. LOG: Attempting download of new URL file:///C:/Users/#user#/AppData/Local/Temp/Temporary ASP.NET Files/vs/0c78498f/ece65cb2/System.Web.WebPages.Deployment/System.Web.WebPages.Deployment.DLL. LOG: Attempting download of new URL file:///C:/Users/#user#/Source/Workspaces/MySystem/MySystem/Frontend.Web/bin/System.Web.WebPages.Deployment.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Stack Trace:

[FileLoadException: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from 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, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence 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: Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +738 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +57 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): Could not load file or assembly 'System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9963380 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1586.0

我之前的评论中提到了解决方案,因为 .NET Framework 下有两个(x86 和 x64)web.config 文件(对于那个版本,4 个): C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.con‌ 图 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config - 然后,当我删除两个文件中的 'System.Web.WebPages.Deployment' 条目时,它起作用了!

我不确定它们是如何添加到项目中的 - 但我怀疑当我尝试使用 GMap.Net (http://greatmaps.wikia.com/wiki/Main_Page) 时出了点问题 - 并且在构建它时遇到了问题。