Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. Manifest definition does not match the assembly reference
Asked Answered
S

37

267

Things I've tried after searching:

  1. in Web.Config put a binding on the old version:

    <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.1.0" />
    </dependentAssembly>
    
  2. Edit my .csproj file to make sure there is only one Newtonsoft reference

    <Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
       <SpecificVersion>False</SpecificVersion>
       <Private>True</Private>
    </Reference>
    
  3. Search my computer for every Newtonsoft.Json.dll and delete every non 6.0.1 version and delete the contents of my temp folder

  4. Repair/Reinstall the package in nuget manager console

It succeeds on building, but gets the error when going to the site.

EDIT

ok, so then I tried to reinstall like every nuget package, and it seems to have added back the 4.5 version of the newtonsoft.json.dll, but I'm getting the same error. My project's Target freamework is .NET 4.5.1 and here is the stack trace I'm getting now:

Server Error in '/' Application.

Could not load file or assembly Newtonsoft.Json or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly Newtonsoft.Json or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly Newtonsoft.Json could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Newtonsoft.Json | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/
LOG: Initial PrivatePath = c:\users\user\documents\visual studio 2013\Projects\foo\bar\bin
Calling assembly : (Unknown).
 ===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\users\user\documents\visual studio 2013\Projects\foo\bar\web.config
LOG: Using host configuration file: C:\Users\user\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/bin/Newtonsoft.Json.DLL.
LOG: Using application configuration file: c:\users\user\documents\visual studio 2013\Projects\foo\bar\web.config
LOG: Using host configuration file: C:\Users\user\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.5.0.0 redirected to 6.0.1.0.
LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///C:/Users/user/AppData/Local/Temp/1/Temporary ASP.NET Files/root/48686d37/9d7a6572/Newtonsoft.Json/Newtonsoft.Json.DLL.
LOG: Attempting download of new URL file:///c:/users/user/documents/visual studio 2013/Projects/foo/bar/bin/Newtonsoft.Json.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Stack Trace:

[FileLoadException: Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]

[FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
       System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
       System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
       System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
       System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
       System.Reflection.Assembly.Load(String assemblyString) +28
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38

[ConfigurationErrorsException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
       System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
       System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
       System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
        System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
       System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
       System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): Could not load file or assembly 'Newtonsoft.Json, Version=6.0.1.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408
Schaerbeek answered 27/3, 2014 at 10:57 Comment(10)
Ok, I've noticed now that when I build the project, in the bin folder, it has the 4.5 version...Schaerbeek
Ok, I think I got it to work now. I deleted every Newtonsoft.Json.dll on my machine that wasn't the latest version that I could find, made sure I had the latest version in NuGet, and build it and made sure that was the latest one in the bin folder, and I left the changes in the web.config and the .csproj. Now I'm on to another error, so it must be working...Schaerbeek
Add the answer to your question so people can see it has been resolved? And mark it as the solutionKeeter
such an annoying DLL hell error, still can't get it to work despite what was said below >.<Dishearten
I'm having some version of this problem even today (3/1/2016) with version 8.0.2. It's trying to load version 6.0.0. No file in my solution references 6.0.0. There's no version 6.0.0. .dll anywhere in my solution area. I have many copies of the newtonsoft.json.dll on my computer, of various versions, they're used by installed 3rd party software that I don't want to mess with. Aside from removing all those copies, I've tried every solution mentioned in this entire thread, and nothing has worked.Pathos
I had also encounter this error message of newtonsoft-json when I added reference of one project to another project but .Net Framework in projects was different after making same .Net Framework on both problem fixed. But I couldn't understand instead of Framework error message why it shows newtonsoft-json related error.Dishpan
Use the Consolidate option in NuGet package manager to ensure versions don't drift apart.Funiculate
Install the same version of Newtonsoft.Json in all your projects, even though their don't use it.Nowlin
similar Q: https://mcmap.net/q/94763/-could-not-load-file-or-assembly-39-newtonsoft-json-version-9-0-0-0-culture-neutral-publickeytoken-30ad4fe6b2a6aeed-39-or-one-of-its-dependencies/492Helix
this is very annoying error. i wouldn't want to use in my next projectHydrolyte
S
19

Ok, I think I got it to work now. I deleted every Newtonsoft.Json.dll on my machine that wasn't the latest version that I could find, made sure I had the latest version in NuGet, and build it and made sure that was the latest one in the bin folder, and I left the changes in the web.config and the .csproj. Now I'm on to another error, so it must be working..

Schaerbeek answered 24/4, 2014 at 15:22 Comment(3)
How did you go about finding all of the locations on your machine?Plead
i got the error also when getting the project by team foundation server to my pc.i add reference of newtonsoft to my solution.it did not work.then i install json.net (newtonsoft.json) through nuget package manager.Now it is working fine.Trabeated
it is inside the bin folder file name -- Newtonsoft.Json.dll Delete this file and reinstall the package or just install lower version and reinstall correct version using NuGet-SolutionMarking
C
322

To solve this, I ensured all my projects used the same version by running the following command and checking the results:

update-package Newtonsoft.Json -reinstall

And, lastly I removed the following from my web.config:

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
  </dependentAssembly>

If you want to ensure all your Newtonsoft.Json packages are the same version, you can specify the version like so:

update-package Newtonsoft.Json -version 6.0.0 -reinstall

Note: To open the PMC in Visual Studio, click Tools -> Nuget Package Manager -> Package Manager Console. Thanks @Rose!

Corene answered 12/11, 2014 at 16:35 Comment(12)
Just running the reinstall command worked for me. I didn't need to modify web.config.Gall
I just had to add the <dependentAssembly> tag to get rid of this error.Ancohuma
I had to provide the -version, but omit the -reinstall flag to make it work in my case.Wescott
@Wescott Then you would have simply updated all packages to the version you specified; not reinstalling them where they were previously installed. Both commands would've worked in your case, I imagine.Corene
I removed the <dependentAssembly></dependentAssembly> block from my web.config that referenced an older version. I then ran "Install-Package Newtonsoft.Json" command in Package Manager Console. This is what worked for me.Alltime
I am using the recent version 9.0.1 but it was showing same error. I then checked the version in csproj file and it was 9.0.0.0, added that to my web.config and problem was solved. 1. Make sure the version in csproj is same as in web.config 2. Beware of the version numbers, it can say x.0.1 when the actual version is x.0.0.0, x can be 6 or 9 or whatever it is.Castlereagh
Note that to run the command in VS2017, you can go in Tools -> Nuget Package Manager -> Package Manager ConsoleSilverman
I just removed the dependentAssembly block which fixed itMcfarlin
In case it can help anyone in the future: for me the error was being caused two projects in one solution using different versions of Newtonsoft.Json.Fencer
Can't fix it. VS 2019. Have tried all the suggestions offered here. Unable to recompile the project.Carn
Removing the dependentAssembly from web.config solved my problem! Thanks!Weymouth
I get "The -Reinstall parameter does not apply to PackageReference based projects."Highbred
I
93

I am using Newtonsoft.Json v6.0.3, but this is what I had to do in my Web.config file:

<dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

Note that even though I am using 6.0.3, I had to put in newVersion="6.0.0.0"

In my packages.config file I have:

<package id="Newtonsoft.Json" version="6.0.3" targetFramework="net45" />
Iniquitous answered 24/6, 2014 at 14:57 Comment(4)
Just as a note, I tried uninstalling/removing/deleting everything that I could find that had to do with Newtonsoft.Json, then using Nuget to reinstall it, but was still receiving the error above. It wasn't until I made the changes I mentioned that I was able to get it to work properly.Iniquitous
I experienced this issue and used the Assembly Binding Log Viewer to help diagnose it. The assembly binder reports the v6.0.3 Newtonsoft.Json.dll as v6.0.0.0 so the redirect would fail when I had it configured as 6.0.3.Mallett
The "Note" line help me. I had initially 9.0.1.19813 as the newVersion in the bindingRedirect since that's what the DLL says. This is what I have now: <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> </Reference> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/> <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/> </dependentAssembly>Filberte
Three years later I'm having the same experience. Changing new version from "12.0.1.0" to "12.0.0.0" fixed the problem.Financial
T
70

I tried the following after having already ensured that my computer had the same version in all locations and that my projects were all pointing to the same reference path. I had also made sure that the binding of the old version was their and bound to the current version of dll that I had.

I work in an environment with a strict framework and the framework team often upset the versioning with the different dll's.

How I fixed this issue was to run the package manager console within visual studio (2013). From there I ran the following command:

update-package Newtonsoft.Json -reinstall

followed by

update-package Newtonsoft.Json

This went through and updated all of my config files and relevant project files. Forcing them all to the same version of the dll. Which was initially version 4.5 before updating again to get the latest.

Trotline answered 3/2, 2015 at 5:3 Comment(3)
It was the update that resolved the issue for me. My project was updated to Newtonsoft version 7.0.Escuage
Worked for me. After doing this, Important to note to make sure your package.config and web.config file have matching versions.Veneration
Worked for me when done from the NuGet Package Manager Console thanks!Hausner
P
25

I had the same error message and, like you mentioned, it was due to different versions of the Newtonsoft.Json.dll being referenced.

Some projects in my MVC solution used the NuGet package for version 4 of that dll.

I then added a NuGet package (for Salesforce in my case) that brought Newtonsoft.Json version 6 with it as a dependency to one of the projects. That was what triggered the problem for me.

To clean things up, I used the Updates section in the NuGet Package Manager for the solution (off Tools menu or solution right-click) to update the Json.Net package throughout the solution so it was the same version for all projects.

After that I just checked the App Config files to ensure any binding redirect lines were going to my chosen version as below.

<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
Pelagian answered 16/5, 2014 at 15:17 Comment(2)
What if DLLs have dependencies for different versions of Newtonsoft.Json for the same MVC app? This is where I am stuck.Outlier
Use the Consolidate option in NuGet package manager to ensure versions don't drift apart.Funiculate
S
19

Ok, I think I got it to work now. I deleted every Newtonsoft.Json.dll on my machine that wasn't the latest version that I could find, made sure I had the latest version in NuGet, and build it and made sure that was the latest one in the bin folder, and I left the changes in the web.config and the .csproj. Now I'm on to another error, so it must be working..

Schaerbeek answered 24/4, 2014 at 15:22 Comment(3)
How did you go about finding all of the locations on your machine?Plead
i got the error also when getting the project by team foundation server to my pc.i add reference of newtonsoft to my solution.it did not work.then i install json.net (newtonsoft.json) through nuget package manager.Now it is working fine.Trabeated
it is inside the bin folder file name -- Newtonsoft.Json.dll Delete this file and reinstall the package or just install lower version and reinstall correct version using NuGet-SolutionMarking
M
8

After hours struggling with this... I did the following:

web.config

<runtime>

  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
    </dependentAssembly>

    <!-- other assemblies... -->

  </assemblyBinding>
</runtime>

The key to enter the correct newVersion and oldVersion number is open the project's References find the package go to its properties or click alt + enter

You'll find a section Version which in my case was 12.0.0.0 while its actually 12.0.3 when exploring with Manage NuGet.

So you need to pick the package's version from the reference properties (in my case 12.0.0.0)

Finally, clean and rebuild the project (you might want to delete the bin and obj folders before).

You might face other packages dependencies issues, i did that for all and they worked.

Multivibrator answered 31/3, 2020 at 7:3 Comment(1)
Deleting the bin and obj folders did the trick for me.Cassel
L
7

By commenting it out this part on my web.config solved my problem:

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>

But of course you need to make sure you have updated or you have the right version by doing this in your package manager console:

update-package Newtonsoft.Json -reinstall
Leonoreleonsis answered 24/10, 2017 at 16:25 Comment(0)
B
6

You can solve the issue by adding below lines in web.config file.

 <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
Begone answered 10/11, 2017 at 10:43 Comment(0)
G
5

In my case it was just a matter of:

Tools -> NuGet Package Manager -> Package Manager Settings -> Clear Cache

The problem was caused when I remapped a TFS folder.

Gar answered 1/6, 2015 at 15:35 Comment(0)
P
4

I have tried the steps by Oleg, and they worked for my same situation.

Steps:

  1. Run update-package Newtonsoft.Json -reinstall in Package Manager.

  2. Delete your bin by enabling viewing the hidden files and deleting the bin folder.

  3. Close your Visual Studio and re-open it.

  4. Now run your project again. I believe it should be ok!

Promenade answered 7/7, 2017 at 23:38 Comment(0)
A
4

from Tools>>NuGet Package Manager>>Manage Package for solution update Newtonsoft.Json of all solutions to latest Version

Andri answered 25/12, 2018 at 11:20 Comment(0)
C
3

In some cases if you delete your Bin and Obj folders will solve this problem.

Cecilia answered 9/5, 2017 at 14:0 Comment(0)
F
3

What actually helped me was to turn off the Resharper build and to use the VisualStudio Re-Build option on my project.

Foliaceous answered 27/11, 2017 at 16:52 Comment(3)
How did you do that?Alleneallentown
In Resharper's options: Tools -> ReSharper Build -> Build Engine - choose "Visual Studio"Foliaceous
I installed a trial version a while ago (about a month, I think) and then I also disabled the extension. I'm not seeing it in Tools, so hopefully I'm OK.Alleneallentown
T
2

if you're working with some kind of subversion: delete the project and re-download it, it worked for me :S

Tambratamburlaine answered 24/9, 2014 at 0:11 Comment(1)
Long way around but I've had to do this as no other solution worked for meMarquand
S
2

I had the same issue on a Test Project that had reference to an MVC 5 project. This happened after I merged with an MVC 5 project. I fixed it by installing Visual studio 2012 updates as explained here in Andre's response.

  • In your visual studio go to
    1. Tools> Extensions And Updates
    2. Select "Updates" in the accordion list on the left.
    3. Select "Product Updates".
    4. Update to the newest version
Stateless answered 27/3, 2015 at 8:55 Comment(0)
G
2

I Don't know why, but in my case, even if I remove bin folder from project, when I build project it copies old version of newtonsoft.json, I copied new version's dll from packages folder and It solves for now.

Glasgo answered 8/11, 2015 at 10:53 Comment(1)
I had a similar issue. In my solution, I have a test project. The test project was getting version 9 in the bin, but the project I was testing had version 12. I copied the version 12 from the project under test's bin folder to the test's bin folder.Culm
H
2

If none of these works, please check this answer:

https://mcmap.net/q/94765/-binding-redirect-problem-in-net

(TL;DR: Remove xml namespace from configuration tag in your config file. Otherwise binding redirects will be ignored)

Helvetii answered 9/6, 2016 at 9:22 Comment(0)
W
2

Alright so I guess the thing to do is add my answer here to this long list versus creating a duplicate question...

If you are getting this in 2019, using .NET Core 3.0 (Preview at this time), the solution is to ensure all projects are targeting the same .NET Core version (in my case 3.0). I think I had one project in the solution targeting 2.1 and the rest were 2.2 so I probably could have stuck with 2.2...

I don't even have Newtonsoft.Json installed in any of the projects, and naturally adding it to them did not fix the issue.

If you have .NET Standard class libraries or w/e in your solution, they don't need to be on the same version, though they should probably be the latest you can go. For example, my .NET Standard class libraries are on 2.2 as there is not a .NET Standard 3.0 yet.

Wadesworth answered 21/6, 2019 at 12:33 Comment(2)
I suspect NET versions is my issue, but this solution won't work: I have an app targeting net6, and app targeting framework48 and shared libraries targeting standard 2.0. The framework app though it doesn't use json directly, the build is shoving a framework newtonsoft library into the build and I can't get the thing to put a standard newtonsoft in :(Highbred
I'm not surprised that you're having a bad time with a Framework 4.8 - .NET 6 environment. You are on the correct .NET Standard (2.0) to support both, but Newtonsoft has been a wildcard since System.Text.Json was released. You should probably create a new question for your issue, I can't think of any suggestions for you :(Wadesworth
S
1

None of the answers, including the checked one did not work for me.

The solution was far more simple. I first removed the references from my BUS layer. Then deleted the dll's from the project (to make sure it's gone), then reinstalled JSON.NET from nuget packeges. And, the tricky part was, "turning it off and on again".

I just restarted visual studio, and there it worked!

So, if you try everything possible and still can't solve the problem, just try turning visual studio off and on again, it might help.

Synchronous answered 1/6, 2015 at 8:41 Comment(1)
I think Simple was sarcasm.Spool
M
1

I resolved it by remove lower version of Newtonsoft.json.dll in bin folder and added Newtonsoft.json.dll V6.0.0.0 and removed the following web.config elements

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
    <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.8"/>
</dependentAssembly>
Metritis answered 8/7, 2017 at 17:4 Comment(0)
A
1

I got the same problem with dotnet core and managed to fix it by clearing the NuGet cache.

Open the powershell and enter the following command.

dotnet nuget locals all --clear

Then I closed Visual Studio, opened it again and entered the following command into the Package Manager Console:

Update-Package

NuGet should now restore all packages and popultes the nuget cache again.

After that I was able to build and start my dotnet core webapi in a Linux container.

Andrew answered 4/10, 2018 at 9:23 Comment(0)
C
1

the solution that solved my problem for this is

goto references->right click Newtonsoft.json--goto properties and check the version

this same version should be in

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-YourDllVersion" newVersion="YourDllVersion" />
</dependentAssembly>
Cretin answered 24/4, 2019 at 9:31 Comment(0)
S
0

Easy steps. (1)Run "update-package Newtonsoft.Json -reinstall" in package manager.

(2)Delete you bin by enabling viewing the hidden files and deleting the bin folder.

(3)Close your visual studio and re-open it.

(4) Now run your project again. I believe it should be ok

Sonorous answered 15/4, 2015 at 10:43 Comment(0)
N
0

I hit this problem because I had: project A (a desktop .exe) refer to project B (a portable .dll). A & B had different versions of JSON.Net, and so there was a loader conflict. Once I made all the versions of JSON.net the same, it worked. (This is in effect what some of the solutions above are doing - I'm just calling out why it works)

Nonary answered 16/5, 2015 at 18:28 Comment(0)
C
0

I struggled with this recently with and older project.

I managed to track down the problem after checking what version of the dll that actually was in the bin folder.

I had a post-build script that copied dependent assemblies from a dll library folder to the bin folder. A common setup from the days before nuget.

So every time I built the post-build script replaced the correct version of Json.net with the older one

Chore answered 27/5, 2015 at 12:0 Comment(0)
M
0

I had exactly the same issue and Visual Studio 13 default library for me was 4.5, so I have 2 solutions one is take out the reference to this in the webconfig file. That is a last resort and it does work.

The error message states there is an issue at this location /Projects/foo/bar/bin/Newtonsoft.Json.DLL. where the DLL is! A basic property check told me it was 4.5.0.0 or alike so I changed the webconfig to look upto 4.5 and use 4.5.

Mavis answered 13/8, 2015 at 14:40 Comment(0)
H
0

None of these options worked for me, in the end it was;

Test > Test Settings > *.testrunconfig

I had to add a new line

<DeploymentItem filename="packages\Newtonsoft.Json.4.5.8\lib\net40\Newtonsoft.Json.dll" />

Make sure the path and version is correct for your setup.

Hickson answered 7/9, 2015 at 22:21 Comment(0)
O
0

This problem was not solved for me by refreshing NuGet Packages or by performing a "Clean" on the project. It was solved by clearing out the "obj" folder manually.

Oligoclase answered 29/6, 2017 at 20:47 Comment(0)
H
0

Here is my solution to this problem,make sure the version number in appconfig or packageconfig is same as the reference version in your references. See here

Hoofer answered 12/10, 2017 at 13:0 Comment(0)
K
0

In my case, at the message of error was "version 6.0.0", but this version is not available to install, so i installed the "6.0.1 version" at my project and solved my problem.

install-package Newtonsoft.Json -Version 6.0.1 -Project MyProjectX
Karolekarolina answered 12/12, 2018 at 14:19 Comment(0)
B
0

my problem was the newVersion in this code in web.config was not correct

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.1.0" />

you can see the version of Newtonsoft.Json package in nuget package manager and use it.

Biscay answered 10/2, 2019 at 9:24 Comment(0)
D
0

What helped me was upgrading the NuGet to the latest version. Hope this helps.

Dubai answered 29/3, 2022 at 4:18 Comment(0)
S
0

After install or update Newtonsoft, some changes occur in web.config and those ones must be moved to web.config in live/prod environment, they are required and it depends which version used of.

We had same problem because we have been using release automation and wen.config file won't be override in prod/staging environment. So web had to change config file manually.

Subcritical answered 21/11, 2022 at 13:20 Comment(0)
P
0

For IIS contexts specifically:

I'd like to mention another angle I don't see covered in other answers. If you are seeing this error in IIS, sometimes it inexplicably retains cached copies of prior versions of DLLs in its temporary directories. If you have checked the version of the DLL in your /bin directory, and you've checked your binding redirects in web.config, and IIS just doesn't seem to “see” the local (correct version) copy of the DLL, here are steps to get to the bottom of it:

  1. Follow the instructions in this answer to turn on assembly bind logging (there is a performance penalty, so remember to turn this off when you're done);
  2. Get the assembly bind log viewer (FUSLOGVW.exe, in the VS SDK, or available from Microsoft); Assembly Bind Log Viewer
  3. Make a request to the site, review the log list to find the binding that's failing
  4. In the log contents, you can see every candidate DLL considered to satisfy a binding request. If you have verified that the copy in your bin directory is correct, inspect the others and remove them if necessary: Fusion Assembly Bind Log Contents
Plunder answered 23/12, 2022 at 15:49 Comment(0)
I
0

For me, it was upgrading to Newtonsoft.Json 13.0.3. If you look at the references of the project and click on Newtonsoft.Json.dll, take a look at the properties. For me, even though NuGet and the package said 13.0.3, the properties version said 13.0.0. Therefore, I decided to put this in the AssemblyBinding section of the web.config, and it worked! :

<dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-13.0.3.0" newVersion="13.0.0.0" />
</dependentAssembly>
Ingratitude answered 6/1, 2024 at 3:50 Comment(0)
R
-1

I had the same issue. I created a web api project and then upgraded it from .net 4.5.1 to .net 4.6.1. Closing the IDE, stopping IIS, and deleting contents of the C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\ dir fixed the issue.

HTH

Romero answered 9/12, 2016 at 1:4 Comment(0)
G
-1

Pls note I had this issue with DESKTOP APP DEVELOPMENT, NOT IN WEB APP DEVELOPMENT. I was redirected here when finding solution, if you are also redirected this way, then you can use GAC (Global Assembly Cache), which is used for storing common DLLs to Global for use.

My Issue in detal: Suppose, I was running app from C:\Documents via CMD with given full app's path D:\MyApp\MyApp.exe which uses Newtonsoft.json.dll and MyDLL.dll for json and processing respectively, which were stored at location D:\MyApp\ folder. Now, at execution time its starts searching DLL in C:\Users\Public which does not have DLLs. Then it gives error of Could not load DLL Newtonsoft.json.dll.

So i ended up registering dll in GAC. You can install in two ways

  1. Use GACUTIL You can find steps in, How do I register a .NET DLL file in the GAC?

Which is simple but is installed with Visual Studio Installation.

  1. Use POWERSHELL if GACUTIL is not available

You can follow Link, https://asvignesh.in/register-dll-in-gac-without-using-gacutil/

Or which Is used (link page description and below description is same) Powershell Commands:

PS C:\WINDOWS\system32> [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

PS C:\WINDOWS\system32> $publish = New-Object System.EnterpriseServices.Internal.Publish PS C:\WINDOWS\system32> $publish.GacInstall("dll path full");

Hope you find your answer.

Genous answered 4/12, 2021 at 7:41 Comment(1)
Installing assemblies in GAC is probably the worst idea. This can create problems for other software vendors which are using the same package. I am so happy that NET Core moved away from this GAC nightmare.Extramarital

© 2022 - 2025 — McMap. All rights reserved.