应用程序正在构建但无法加载 - System.Web.Mvc缺少文件或程序集?

时间:2014-11-19 20:28:48

标签: c# asp.net asp.net-mvc tfs asp.net-mvc-5

我最近在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

修改

虽然我没有收到Build的任何错误,但我收到以下警告(关于第一个,不知道如何将“log verbosity”设置为“详细”):

enter image description here

EDIT2

所以,我不知道发生了什么变化,但今天早上我System.Web.Mvc的属性是可选的,我可以将Copy Local属性转换为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

有人想过从哪里开始?

引用 this 帖子,我挖到我的bin文件夹,发现System.Web.Mvc.dll文件是版本{{1定义我在4.0.20710.0文件中适当地相信:

Web.config

EDIT3

查看 this 文章,我确保所有列出的参考文献确实在我的应用程序中:

References

当我在列表中没有看到<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> 时,我认为我发现了问题,但似乎并非如此:

Microsoft.Web.Infrastructure

EDIT4 - (周恩来的建议):

  • 1.)在Visual Studio中,转到Tools =&gt;扩展和更新。如果有更新NuGet更新它,然后关闭并重新打开该项目。可能是软件包已经更改,如果您没有最新版本,软件包将不会像应该的那样自动更新。

VS2013(更新4)有更新,但仍然存在同样的问题。

  • 2.)删除bin / obj目录。清理解决方案并不总是完全清理,并且您可能在其中一个目录中有一个旧程序集。

我按照指示清除了这些文件夹,现在我的项目无法构建,出现43个错误。其中大多数涉及无法找到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'. The type or namespace nameDbSet,以及Entity / DbMigration各一个。似乎导致所有其他错误的大错误如下:

DbMigrationsConfiguration

然后我尝试通过Nuget命令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. 添加指定的包和版本,结果导致:

Install-Package EntityFramework -Version 6.0.0

对此的想法?

  • 3.)在Web.Config中查看runtime =&gt; assemblyBinding部分中的绑定重定向。新版本值应为较新版本。

我已复制下面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 的{​​{1}}部分。我没有看到任何错误:

<runtime><assemlbyBinding>
  • 4。)查看每个项目中的每个程序集,找到使用错误版本的程序集。删除引用并重新添加。

我在这个特定的解决方案中只有一个项目。我不确定哪个组件是错误的版本?

2 个答案:

答案 0 :(得分:4)

有些事情可能导致这种情况,当我遇到这个问题时,我会做这些事情:

1。)在Visual Studio中,转到Tools =&gt;扩展和更新。如果有更新NuGet更新它,然后关闭并重新打开该项目。可能是软件包已经更改,如果您没有最新版本,软件包将不会像应该的那样自动更新。

2.删除bin / obj目录。清理解决方案并不总是完全清理,并且您可能在其中一个目录中有一个旧程序集。

3.)在Web.Config中查看runtime =&gt; assemblyBinding部分中的绑定重定向。新版本的值应该是较新的版本。

4。)查看每个项目中的每个程序集,找到使用错误版本的程序集。删除引用并重新添加它。

答案 1 :(得分:0)

我们与Autofac一起使用了。原来是web.config中的错误合并

我们在一个assemblyIdentity节点中有两个dependentAssembly节点。本质上,合并剥离了一个结束标签和一个开始标签。它位于assemblyBinding块的顶部,似乎已删除了紧随其后的所有绑定重定向。

我们当然看过的最后一个地方...

相关问题