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

前端 未结 18 1740
夕颜
夕颜 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:43

    Have you tried through NuGet ?

    Install-Package WebGrease -Version 1.5.1
    

    or

    Install-Package WebGrease -Version 1.5.2
    
    0 讨论(0)
  • 2021-01-31 07:44

    In my case this was not solved by any of the solutions above. The error relating to webgrease was actually a red herring ... it was a problem with an invalid (and completely unrelated) assembly binding redirect. I guess this problem with my web.config file was causing all the assembly binding redirects to fail, and it just so happened this was causing a runtime issue with WebGrease.

    Basically, during a merge one of the binding redirects had got corrupted and it had ended up with two assembly redirects within a single <dependentAssembly> tag.

    So, if you are getting this issue and you already have the binding redirect set up correctly for WebGrease, it is worth scanning through all your other assembly binding redirects to check that non of them have been corrupted.

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

    When you redirect webgrease make sure you don't have an appliesTo attribute on your assemblyBinding element. For me I removed it completely.

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

    I know it's kind of late for the OP but I ran into the same problem while trying out the Bootstrap 3 for MVC 4 NuGet package, in my case it had something to do with the Microsoft.AspNet.Web.Optimization package, and managed to find a simple solution.

    Try executing the following commands in the package manager console:

    Install-Package Microsoft.AspNet.Web.Optimization
    Update-Package WebGrease
    Uninstall-Package Microsoft.AspNet.Web.Optimization
    Uninstall-Package WebGrease
    Install-Package Microsoft.AspNet.Web.Optimization
    Update-Package WebGrease
    

    The first two lines had no effect for me since those packages were already installed and updated by the Bootstrap 3 for MVC 4 package, but I ran them anyway and then it all compiled and ran great.

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

    For me, none of above scenarios worked.

    After trying for two days, finally i found the solution.

    What i did was, i uninstalled Microsoft.AspNet.Web.Optimization and WebGrease both.

    I knew that this optimization assembly internally refers to WebGrease 1.5.1. So i chose a version of optimization which does not refer to WebGrease 1.5.1.

    I ran following commands in order to make everything work.

    Uninstall-Package Microsoft.AspNet.Web.Optimization
    Uninstall-Package WebGrease
    Install-Package Microsoft.AspNet.Web.Optimization -Version 1.1.0
    

    I hope i will be able to be a good help for someone for whom above solution does not work.

    Cheers!

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

    The issue I observed matched closely what Jidheesh Rajan mentioned. However, updating the package from Nuget package manager (without specifying version) did not fix the issue. Here is what I had to do to fix the issue. (Essentially, I explicity updated WebGrease to version 1.6)

    From within the package manager console in Visual Studio, explicitly update WebGrease to version 1.6 . here is the command.

    Install-Package WebGrease -Version 1.6
    

    Output should be

    Removing 'WebGrease 1.5.2' from {project name}
    

    Adding 'WebGrease 1.6.0' to {project name} Successfully added 'WebGrease 1.6.0' to {project name} Uninstalling 'WebGrease 1.5.2'. Successfully uninstalled 'WebGrease 1.5.2'.

    This ended up updating web.config with

        assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" /
        bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" 
    

    This also resulted in the removal of a line from the csproj file.

    <WebGreaseLibPath>..\packages\WebGrease.1.5.2\lib</WebGreaseLibPath>
    

    and an update in this node in the csproj file

    <Reference Include="WebGrease, Version=1.5.2.14234, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
      <SpecificVersion>False</SpecificVersion>
      <Private>True</Private>
    </Reference>
    

    to this

    <Reference Include="WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <HintPath>..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
      <SpecificVersion>False</SpecificVersion>
      <Private>True</Private>
    </Reference>
    

    Keep in mind that I didnt have an issue on my local machine, just on a stage web server. I wanted to try my best to resolve the issue without updating the package, but this was the only fix I had.

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