3

I am trying to use JSON.NET and after including the .dll and trying to use one of the methods I get this error:

Could not load file or assembly 'Newtonsoft.Json.Net35, Version=4.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

Any know why I might be this error?

ryanzec
  • 27,284
  • 38
  • 112
  • 169

4 Answers4

0

try to add assembly binding redirect to app config like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.5.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

Related posts:

System.IO.FileNotFoundException

At least one module has an unresolved import

Debugging tests that require an external dll

Community
  • 1
  • 1
Vladimir Shmidt
  • 2,651
  • 1
  • 19
  • 21
0

Two things to check:

(1) You may have to "Unblock" the DLL. By default, when you download a .zip file from the Internet, that file, and all .dll or .exe files extracted from that .zip file, are given a file system attribute that prevents them from loading and executing. Right-click on the DLL in Windows Explorer, choose "Properties", and in the resulting dialog box click on the "Unblock" button. Or better yet, do that for the .zip file, and then re-extract all the files.

(2) The Newtonsoft JSON.NET library comes in five flavors: one each for .NET 2.0, 3.5, 4.0, Silverlight, and Windows Phone. You need to use the right one for your particular environment. I presume that this is a .NET 3.5 project?

Ken Smith
  • 20,305
  • 15
  • 100
  • 147
  • there is no unblock option in windows 7 but everything else looks fine. my console project is setup as for the 3.5 framework. – ryanzec Feb 06 '11 at 22:35
  • @ryanzec - You would "unblock" it using the "caspol.exe" utility. This is install with .NET 2.0. It's typically under "C:\Windows\Microsoft.NET\Framework\v2.0.50727". You probably have this installed. ;-) – Enigmativity Feb 06 '11 at 23:15
  • does not seem like unblocking is the issue. – ryanzec Feb 06 '11 at 23:46
  • You could also do an 'unblock' on the zip-file before you unzip. – Kjetil Klaussen Feb 07 '11 at 14:59
0

In my case, I resolved this problem once I realized that a library that I was using was itself using the Json.NET but with the earlier version (3.5). Linking the second library to the new Json.NET version solved the issue.

Hope this helps.

Stefano Ricciardi
  • 2,923
  • 3
  • 33
  • 40
0

You need to download release 1 instead of release 2 of the Newtonsoft.Json.

Fabio Milheiro
  • 8,100
  • 17
  • 57
  • 96