簡體   English   中英

應用程序正在構建但無法加載 - System.Web.Mvc缺少文件或程序集?

[英]App is building but failing to load - System.Web.Mvc missing file or assembly?

我最近在TFS的一個MVC項目上做了“Get Latest”,現在當我嘗試運行它時,每次結果都是黃色的失敗屏幕,說明:

Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

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.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error: 


Line 17:             RouteConfig.RegisterRoutes(RouteTable.Routes);
Line 18:             BundleConfig.RegisterBundles(BundleTable.Bundles);
Line 19:         }
Line 20:     }
Line 21: }

Source Line: 19

有問題的文件粘貼在下面:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace PROJECTdev
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

任何人都有任何想法,為什么會發生這種情況,以及如何解決它?

到目前為止,我已嘗試清理/構建解決方案,甚至在TFS中進行了迄今為止刪除我當前的映射並執行全新的項目地圖/下載 - 這導致了進一步的問題,但畢竟麻煩通過修復破損的參考資料來解決它們,我正好回到正方形......

任何幫助贊賞。

如果有幫助,我已粘貼下面的裝配負載跟蹤:

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

=== Pre-bind state information ===
LOG: DisplayName = System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/
LOG: Initial PrivatePath = C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\bin
Calling assembly : PROJECTdev, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\web.config
LOG: Using host configuration file: C:\Users\jsmith\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 5.1.0.0.
LOG: Post-policy reference: System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.EXE.
LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.EXE.
LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc/System.Web.Mvc.EXE.

堆棧跟蹤:

[FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]

[FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   PROJECTdev.MvcApplication.Application_Start() in c:\john-Projects\PROJECT\PROJECTdev\PROJECTdev\Global.asax.cs:19

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9936485
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

編輯

雖然我沒有收到構建的任何錯誤,但我收到以下警告(關於第一個,不知道如何將“log verbosity”設置為“詳細”):

在此輸入圖像描述

編輯2

所以,我不知道發生了什么變化,但今天早上我的System.Web.Mvc屬性是可選的,我能夠將Copy Local Property變為True 現在,當我運行應用程序時,我得到以下內容:

Server Error in '/' Application.

Could not load file or assembly 'System.Web.Mvc' 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.Mvc' 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.Mvc' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = System.Web.Mvc
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: System.Web.Mvc | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/
LOG: Initial PrivatePath = C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\web.config
LOG: Using host configuration file: C:\Users\jSmith\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.DLL.
LOG: Using application configuration file: C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\web.config
LOG: Using host configuration file: C:\Users\jSmith\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 5.1.0.0.
LOG: Post-policy reference: System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.DLL.
LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.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.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.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) +34
   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) +16
   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.Mvc, Version=5.1.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) +752
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.1.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) +9950728
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

有人想過去哪里?

參考這篇文章,我挖到我的bin文件夾,發現System.Web.Mvc.dll文件是版本4.0.20710.0並且我已經定義了我的Web.config文件:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>

編輯3

看一下這篇文章,我確保所有列出的參考文獻確實在我的應用程序中:

參考

當我在列表中沒有看到Microsoft.Web.Infrastructure時,我以為我發現了這個問題,但似乎並非如此:

PM> Install-Package Microsoft.Web.Infrastructure
'Microsoft.Web.Infrastructure 1.0.0.0' already installed.
PROJECTdev already has a reference to 'Microsoft.Web.Infrastructure 1.0.0.0'.

EDIT4 - (周恩來的建議):

  • 1.)在Visual Studio中,轉到Tools => Extensions and Updates。 如果有更新NuGet更新它,然后關閉並重新打開該項目。 可能是軟件包已經更改,如果您沒有最新版本,軟件包將不會像應該的那樣自動更新。

VS2013(更新4)有更新,但仍然是同一個問題。

  • 2.)刪除bin / obj目錄。 清理解決方案並不總是完全清理,並且您可能在其中一個目錄中有一個舊程序集。

我按照指示清除了這些文件夾,現在我的項目無法構建43個錯誤。 其中大多數涉及無法找到The type or namespace nameDbSetEntityDbMigration / DbMigrationsConfiguration各一個。 似乎導致所有其他錯誤的大錯誤如下:

The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.

然后我嘗試通過Nuget命令Install-Package EntityFramework -Version 6.0.0添加指定的Package和Version,結果是:

PM> Install-Package EntityFramework -Version 6.0.0
Updating 'EntityFramework' from version '6.1.0' to '6.0.0' in project 'PROJECTdev'.
Install-Package : Updating 'EntityFramework 6.1.0' to 'EntityFramework 6.0.0' failed. Unable to find a version of 'Microsoft.AspNet.Identi
ty.EntityFramework' that is compatible with 'EntityFramework 6.0.0'.
At line:1 char:16
+ Install-Package <<<<  EntityFramework -Version 6.0.0
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

對此的想法?

  • 3.)在Web.Config中查看runtime => assemblyBinding部分中的綁定重定向。 新版本值應該是較新的版本。

我已經復制了下面的Web.config <runtime><assemlbyBinding>部分。 我沒有看到任何錯誤:

   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  • 4.)查看每個項目中的每個程序集,找到使用錯誤版本的程序集。 刪除引用並重新添加它。

我在這個特定的解決方案中只有一個項目。 我不確定哪個組件是錯誤的版本?

一些事情可能會導致這種情況,當我遇到這個問題時,我會做以下事情:

1.)在Visual Studio中,轉到Tools => Extensions and Updates。 如果有更新NuGet更新它,然后關閉並重新打開該項目。 可能是軟件包已經更改,如果您沒有最新版本,軟件包將不會像應該的那樣自動更新。

2.)刪除bin / obj目錄。 清理解決方案並不總是完全清理,並且您可能在其中一個目錄中有一個舊程序集。

3.)在Web.Config中查看runtime => assemblyBinding部分中的綁定重定向。 新版本值應該是較新的版本。

4.)查看每個項目中的每個程序集,找到使用錯誤版本的程序集。 刪除引用並重新添加它。

我們和Autofac一起做了這個。 原來是web.config中的錯誤合並

我們在一個dependentAssembly節點中有兩個assemblyIdentity節點。 基本上合並剝離了結束標記和開始標記。 它位於assemblyBinding塊的頂部,似乎已經淘汰了它后面的所有綁定重定向。

我們看的最后一個地方當然......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM