Application Builds But Won't Load - System.Web.Mvc File or Assembly Missing?

I recently got a "Get Latest" on an MVC project in TFS and now when I try to start it, every time the result is a yellow crash screen that says:

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

      

This file is inserted below:

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);
        }
    }
}

      

Anyone have any ideas on why this is happening and how to fix it?

I have tried so far to clean / compile the solution and even went so far in TFS to remove the current mapping and make a completely new map / Project upload - this will lead to further problems, but after all the troubles with fixing them with fixing broken links etc. etc., I will return to square ...

Any help was appreciated.

I've added a screenshot of the assembly loading below if that helps:

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.

      

Stack trace:

[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

      

EDIT

While I don't get any errors for the build, I get the following warning (regarding the first, I don't know how to set "verbosity" to "verbose"):

enter image description here

EDIT2

So, I don't know what changed, but this morning my Properties for System.Web.Mvc

were selected and I was able to turn the Copy Local

Property into True

. Now when I run the application, I get the following:

Server Error in '/' Application.

Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly 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 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 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 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 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 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

      

Anyone have any thoughts on where to go from here?

While referencing this post, I put in my folder and found that the file has a version and is defined, which I deem appropriately in the file : 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>

      

EDIT3

Taking a look at this article , I made sure that all the links listed are indeed in my application

References

When I didn't see it Microsoft.Web.Infrastructure

on my list, I thought I found the problem, but it doesn't seem to be the case:

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 - (Honorable Chow Chow Offer):

  • 1.) In Visual Studio, go to Tools => Extensions and Updates. If the NuGet update is up to date, close and restart the project. It is possible that the packages have changed and if you do not have the latest version, the packages will not automatically update as they should.

Was updated by VS2013 (update 4) but still the same problem.

  • 2.) Remove the bin / obj directories. Clearing the solution doesn't always clear completely and you may have an old assembly in one of these directories.

I cleared these folders as instructed and now my project cannot build with 43 errors. Most of them are related to the inability to find The type or namespace name

: DbSet

, Entity

and one for DbMigration

/ DbMigrationsConfiguration

. The big error that everyone else seems to be causing is this:

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.

      

Then I tried to add the specified package and version using the Nuget command Install-Package EntityFramework -Version 6.0.0

which resulted in:

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

      

Thoughts on this?

  • 3.) In Web.Config, look at the binding redirection under runtime => assemblyBinding. The newer version value must be a newer version.

I copied the section <runtime><assemlbyBinding>

Web.config

below. I don't see anything wrong:

   <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.) Look at each of the assemblies in each of the projects and find the one using the wrong version. Remove the link and add it again.

I only have one project in this particular solution. I'm not sure which assembly is the wrong version?

+3


source to share


2 answers


Several things can cause this, when I have this problem, I do the following:

1.) In Visual Studio, go to Tools => Extensions and Updates. If the NuGet update is up to date, close and restart the project. It is possible that the packages have changed and if you do not have the latest version, the packages will not automatically update as they should.

2.) Remove the bin / obj directories. Clearing the solution doesn't always clear completely and you may have an old assembly in one of these directories.



3.) In Web.Config, look at the binding redirection under runtime => assemblyBinding. The newer version value must be a newer version.

4.) Look at each of the assemblies in each of the projects and find the one using the wrong version. Remove the link and add it again.

+4


source


We had this combined with Autofac. Turned out to be bad merge in web.config

We had two nodes assemblyIdentity

inside one node dependentAssembly

. Basically, concatenation removes the end tag and the start tag. It was at the top of the block assemblyBinding

and apparently knocked out all subsequent bind redirects.



The last place we saw of course ...

0


source







All Articles