Could not load file or assembly System.Web.Mvc or one of its dependencies

前端 未结 3 1442
无人及你
无人及你 2021-02-14 02:44

currently working on asp.net mvc5 (old mvc3 project). It builds just fine, but when I start the project but when I run the project I am facing the following error.



        
相关标签:
3条回答
  • 2021-02-14 03:27

    Could you post your web.config file here?. It seems that you opened a mvc3 project in a newer environment and the migrating function of your IDE (i.e. Visual Studio) doesn't work well. The versions of System.Web.Mvc.DLL are mismatched (in config file and the one in bin/ directory). There are two ways to solve this: 1. Modify the version of System.Web.Mvc package/assembly in the config file. 2. Copy System.Web.Mvc.dll from your old project to the new project (bin/ folder).

    I had faced the similar issue for other .dll files before. At that time, I chose to delete all .dll files and use NuGet Package Manager to download them again.

    0 讨论(0)
  • 2021-02-14 03:37

    I'm not really sure if this will help. But I also had this message:

    Could not load file or assembly 'System.Web.Mvc (1)' or one of its dependencies ...


    I don't really know why but when I check out the bin folder of the web application, some of the DLL files have duplicates like "System.Web.Mvc(1).dll" and so on.

    What I did was, I deleted all the duplicate files (file names with '(1)' or '(2)' ... on it), then rebuild the web app then it worked again.

    0 讨论(0)
  • 2021-02-14 03:44

    If you carefully read the fusion log you posted, it gives you the information you need. I'll strip it down to the important lines.

    LOG: Attempting download of new URL file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/bin/System.Web.Mvc.DLL.
    

    The app is looking for System.Web.Mvc.dll. It's resolved it to the one under your web app's bin folder: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\bin\System.Web.Mvc.DLL

    Next, it checks to see if there is any assembly binding redirect for that DLL in your web.config, and finds one:

    LOG: Using application configuration file: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\web.config
    LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0.
    LOG: Post-policy reference: System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    

    If you look in your web.config, there will be something like this:

      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    

    It then checks that the System.Web.Mvc.dll it's found in your app's bin directory is the same version:

    WRN: Comparing the assembly name resulted in the mismatch: Major Version
    ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
    

    It complains that the Major Version mismatches. This is the first number in the 4-number version. If you go back in the log, that's because the System.Web.Mvc.dll in your bin folder is actually version 4.0.0.1, not the desired 5.2.3.0:

    LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0.
    

    You need to check your solution to make sure all projects that reference System.Web.Mvc are looking for the same, latest version. If you look at the Warnings in the Error List, you'll likely find warnings about version mismatches for this assembly.

    Updating References

    One solution is to right click on the Solution in Visual Studio, choose "Manage NuGet Packages for Solution..." and try to update the projects to use the same version of System.Web.Mvc.

    It will also help if you clear out your bin folders beforehand.

    You can also use the Package Manager Console instead to update the package across your solution:

    Update-Package Microsoft.AspNet.Mvc -version 5.2.3.0
    
    0 讨论(0)
提交回复
热议问题