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

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

    The other answers did not resolve this for me. We are adding a newer MVC 5 API project and it wasn't playing nice with the older MVC 2 API's. After running package updates I was getting the mentioned error. The resolution for me was to remove the WebGrease references added by NuGet in the web.config's of the offending projects.

    To Resolve: Open the web.config of the project(s) throwing the exception and delete or comment out the dependency added for WebGrease.

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

    I used "Install-Package Microsoft.AspNet.Web.Optimization" (current version is 1.1.3) for starup web-project, which was not selected in NuGet console by default.

    But NuGet has created a new app.config file even though web.config is expected to be updated.

    For me it worked to move WebGrease dependentAssembly element from app.config to web.config's <runtime><assemblyBinding>...</assemblyBinding></runtime>.

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

    Alreasy resolved this error. Situation was simpler than i thought. When you install from nuget new version of System.Web.Optimization it has reference to

    // References: WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35

    At same time i have WebGrease version 1.5.2.14234. Running project, we have this error: Could not load file or assembly 'WebGrease, Version=1.5.1.25624

    Soo, i try to check this version on nuget and was surprized, that it wasn't...but when i create new project with VS - i got it. To hack this error i try to install it in GAC..but gac says me, that this lib is not subscribed. Downgrading to System.Web.Optimization Version=1.1.0.0 , where reference is:

    // References: WebGrease, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

    and 1.3.0.0 is strongly subscribed - helped me. It works. After upgrading webgrease, i have it Version=1.6.5135.21930 and it worked perfectly.

    At conclusion, i have an opinion, than this error (Could not load file or assembly 'WebGrease, Version=1.5.1.25624) was because of that System.Web.Optimization lib is referenced to unsubscribed webgrease dll version.

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

    I had this issue during a deployment.

    I copied WebGrease.dll to production, but I forgot to update the Web.Config file as well.

    <configuration>
        <runtime>
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
    </configuration>
    
    0 讨论(0)
  • 2021-01-31 07:38

    Since I wasn't able to uninstall using package manger console, I manually went to packages.config and comment out the older version.

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

    I've faced the excat same issue and managed to fix it by doing the following:

    1. Uninstalling the Microsoft.AspNet.Web.Optimization nuget package.
    2. Uninstalling the Antlr nuget package because its a dependecy for WebGrease package.
    3. Uninstalling the WebGrease nuget package.
    4. Install Microsoft.AspNet.Web.Optimization nuget package again, this action will take care of installing Antlr and WebGrease because they are its dependencies.
    0 讨论(0)
提交回复
热议问题