Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies

前端 未结 18 1722
夕颜
夕颜 2021-01-31 07:02

I have an MVC4 Web API project. While running the service project I am getting an error

Could not load file or assembly \'WebGrease, Version=1.5.1.25624,

相关标签:
18条回答
  • 2021-01-31 07:24

    Tried a lot of things but this worked for me sometimes webgrease assembly issues sometimes Web.Optimization assembly issues. This worked for me with Microsoft.AspNet.Web.Optimization 1.1.3

    Update-Package WebGrease -Version 1.6
    
    0 讨论(0)
  • 2021-01-31 07:24

    This problem may also arise if you do not deploy Web.config file to the web server.

    0 讨论(0)
  • 2021-01-31 07:25

    Here is what I did to get around it,

    1. I saved a copy of the Web.config file of my current (corrupted project) to "Corrupted-Web.Config". and close the project solution.
    2. Created a new application with the same type of my courrpted project. called it ProjTemp.
    3. Save and Run the "PorjTemp", then Save a copy of the Web.Config to "OrigTemp_Web.config"
    4. Close the Web.config files.
    5. On the "ProjTemp" open Tools --> "NuGet Package Manager" --> "Manage NuGet Packages for Solutions" ---> Select to Update all related installed packages. 6 Now Open the newly updated Web.config file. Copy the get the info from the Updated "" Starting from "

    <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
                 --- Copy this section to replace in the corrupted file.---
           </assemblyBinding>
    </runtime>
    

    1. Save your project. Rebuild and Run. Hope this will help! ....

    Here is the corrected one for example, VS2015.


    <runtime>
               <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                     <dependentAssembly>
                            <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
                            <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
                     </dependentAssembly>
                    <dependentAssembly>
                            <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                            <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
                  </dependentAssembly>
                  <dependentAssembly>
                            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
                            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /
                  </dependentAssembly>
                  <dependentAssembly>
                            <assemblyIdentity name="Microsoft.Owin" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" /
                    </dependentAssembly>
                    <dependentAssembly>
                            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
                    </dependentAssembly>
                    <dependentAssembly>
                            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                            <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
                     </dependentAssembly>
                     <dependentAssembly>
                            <assemblyIdentity name="Microsoft.Owin.Security" culture="neutral" publicKeyToken="31bf3856ad364e35" />
                             <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
                      </dependentAssembly>
                      <dependentAssembly>
                             <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
                            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
                       </dependentAssembly>
              </assemblyBinding>
      </runtime>
    

    that's what I have done to fix it, Solution on Github Sami, Oweis 4 Computer

    0 讨论(0)
  • 2021-01-31 07:27

    VS 2017 seems to have the problem of not deploying the web.config, even though the properties for the file are set to 'copy always'. In my project, I have to swap out different web.config files for various deployment scenarios. And the 'webgrease' error will appear if it did not deploy the file.

    Just verify that the web.config file gets deployed.

    0 讨论(0)
  • 2021-01-31 07:29

    This error is because Microsoft.AspNet.Web.Optimization 1.1.3 internally references WebGrease 1.5.1.25624 even though the Nuget package, itself, has a dependency on WebGrease 1.5.2.14234. Someone clearly messed up while creating the Nuget package.

    To solve this, add this assembly binding in your Web.Config.

      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.1.25624" newVersion="1.5.2.14234" />
      </dependentAssembly>
    
    0 讨论(0)
  • 2021-01-31 07:31

    Oldie but goldie...

    I was working on a MVC 5 project in Visual Studio 2013, and I had the same problem. We were using Visual SVN for the versioning and I was the only one in my team that had this problem.

    The only thing that worked for me was this:

    1. Uninstall Microsoft.AspNet.Web.Optimization
    2. In Nuget command prompt run: install-package Microsoft.AspNet.Web.Optimization -Version 1.0.0

    This will install an older version of Web.Optimization. The project was initially referencing version 1.1.0. The problem is not with WebGrease, but with the System.Web.Optimization.dll that is referencing an old, inexisting version of WebGrease.

    When I ran the project, it worked, but I wanted to use the same package version as the rest of team. So, I tried to update but... the error returned...

    After this, I deleted the project (again) and took it back from the SVN. To my surprize, it started to work... The thing is that I had deleted the project completely and took it from the SVN several times before this. I even took the dlls from a colleague because I thought that maybe I'm getting corrupted files from NuGet, but to no avail.

    I hope this will help someone, someday.. with Visual Studio 2016 and MVC 8 :)

    0 讨论(0)
提交回复
热议问题