Does Hangfire have a dependency on Newtonsoft.Json, Version=4.5.0.0

I use Hangfire core 1.5.2 , everything works fine as i was using the Newtonsoft.Json version came with the Hangfire installation ( Which was 4.5). As part of the project requirement we upgraded to latest version of Newtonsoft.Json - 7.0 and my Hangfire starts breaking. Our company do have a pro version , and we are evaluating this software for wider usage. Any pointers to what i am doing wrong here ?

The dashboard is giving me the following error

Could not load file or assembly ‘Newtonsoft.Json,
Version=4.5.0.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)

Here is the stack trace.

[FileLoadException: Could not load file or assembly ‘Newtonsoft.Json, Version=4.5.0.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)]
Hangfire.Dashboard.Pages.HomePage.Execute() +0
Hangfire.Dashboard.RazorPage.TransformText(String body) +31
Hangfire.Dashboard.RazorPageDispatcher.Dispatch(RequestDispatcherContext context) +146
Hangfire.Dashboard.<>c__DisplayClass8.b__4(IDictionary`2 env) +467
Microsoft.Owin.Mapping.d__0.MoveNext() +462
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13908768
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +203
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13908768
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__2.MoveNext() +193
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +96
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +363
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157

Hangfire.Core package requires Newtonsoft.Json 5.0 and higher since 0.7.0 release. Do you have any other packages that require Newtonsoft.Json 4.5?

Not really, all i am running is a simple web application which basically hosts the dashboard. The dashboard works fine if i just drop the 5.0 version of Newtonsoft.Json. And breaks with 7.01 version.
A similar behavior i noted earlier also with the 6.xx version of NewtonsoftJson

Hi,

You need an assembly binding redirect in your app/web.config:

<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-7.0.0.0” newVersion=“7.0.0.0” />
</dependentAssembly>

</assemblyBinding>
</runtime>

</configuration>

HTH

Cool you made my day !! I made the redirect and it is working fine :smile:

I am also using version 1.8.0-beta3 of Hangfire.Core and Version 12.0.3 of Newtonsoft.Json, as hangfire.core.nuspec specified Hangfire.Core 1.8.0 is depended on newtonsoft 5.0.1 and higher versions but still got below exception while enqueueing new job:

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.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)

I don’t want using any assembly redirect config in app.config.
2021-11-07 16_42_36-MNS - Microsoft Visual Studio (Administrator)

The source of Hangfire.Core, does it mean that is depend on Newtonsoft.Json.4.5.0.0 ?