I keep getting this error although I already installed the nuget packet for Microsoft.AspNet.Web.Optimization...

Could not load file or assembly 'System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Apparently, the one in the Nuget is a v.1.13 while the one referenced in my solution somewhere is v.1.0.0 ...Problem is, I can't find the way to match these two. I can't find the install for v.1.0.0 or the way to delete or override the 1.0.0 for the 1.1.3.

Any help on this?

Any code you need to see, let me know and I'll update the question.

5

There are 5 answers

3
cliffeh On BEST ANSWER

I was able to fix this issue by adding the following to my web.config:

<configuration>
    <runtime>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.1.3.0" />
        </dependentAssembly>
    </runtime>
</configuration>
0
0014 On

I think you have to change your "Target Framework", from your project properties. ".Net Framework 3.5" should be fine.

Another thing you must be sure that your "Platform target" is set right. You can change it from your project properties under the "Build" tab. If your running application is 64 bit, change it to x64 otherwise (32 bit) keep it x86. Be careful not to select "Any CPU".

Hope these will help you.

Arif.

0
cda01 On

The projects I am working on are .Net 4.5~ and I had this issue after

  1. Installing the following Nuget Package:

    Install-Package Microsoft.AspNet.Web.Optimization -Version 1.1.3

  2. Adding the following script tag to an *.aspx page:

    <%: Scripts.Render("~/bundles/YourScriptsBundleName") %>

  3. Upating the web.config with:

    <namespaces> <add namespace="System.Web.Optimization"/> </namespaces>

So to fix the problem, I followed cliffeh's answer above but with one slight change:

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.1.0.0" />
  </dependentAssembly>
0
theodor.johannesen On

I ran into the same problem today by switching between branches in GIT.

If you want to use nuget to access a specific version of a package, there is a -version <value> option to very package, that have been installed.

Hence you could writeup an nuge uninstaller, then a nuget installer of the specific package with the additional version information.

0
waffles On

Here's how I fixed it. Re-installing the package using the command:

Install-Package Microsoft.AspNet.Web.Optimization

If you've already got it installed, you'll have to remove this line from packages.config:

<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />