0

I'm getting the following exception when my Azure WebJob handler starts up:

System.IO.FileLoadException was unhandled FileName=Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
FusionLog==== Pre-bind state information === LOG: DisplayName = Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed (Fully-specified) LOG: Appbase = file:///C:/Programming/ConnellCampaigns/src/UploadProcessor/bin/Debug/net46/win7-x64/ LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.Azure.WebJobs.Host, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Programming\ConnellCampaigns\src\UploadProcessor\bin\Debug\net46\win7-x64\UploadProcessor.exe.Config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 6.0.0.0 redirected to 6.0.0.0. LOG: Post-policy reference: Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed LOG: Attempting download of new URL file:///C:/Programming/ConnellCampaigns/src/UploadProcessor/bin/Debug/net46/win7-x64/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.

HResult=-2146234304 Message=Could not load file or assembly 'Newtonsoft.Json, Version=6.0.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)
Source=Microsoft.Azure.WebJobs.Host StackTrace: at Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueWriter1.<EnqueueAsync>d__0.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueWriter`1.EnqueueAsync(T message, CancellationToken cancellationToken) at Microsoft.Azure.WebJobs.Host.Loggers.PersistentQueueLogger.LogHostStartedAsync(HostStartedMessage message, CancellationToken cancellationToken) at Microsoft.Azure.WebJobs.Host.Executors.JobHostContextFactory.LogHostStartedAsync(IFunctionIndex functionIndex, HostOutputMessage hostOutputMessage, IHostInstanceLogger logger, CancellationToken cancellationToken) at Microsoft.Azure.WebJobs.Host.Executors.JobHostContextFactory.d__b.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.Host.Executors.JobHostContextFactory.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.JobHost.d__f.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.JobHost.d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.WebJobs.JobHost.Start() at Microsoft.Azure.WebJobs.JobHost.RunAndBlock() at UploadProcessor.Program.Main(String[] args) in C:\Programming\ConnellCampaigns\src\UploadProcessor\Program.cs:line 25 InnerException:

This only happens if I specify the latest version - 9.0.1 - of NewtonSoft's JSON assembly in project.json.

I can make the error go away by specifying the last v6 issue of the library (6.0.8). But that introduces dependency warnings.

I don't understand why Microsoft.Azure.WebJobs.Host insists on an older version of the library. Its nuget page says it's compatible with any version >= 6.0.8.

How do I resolve this?

Mark Olbert
  • 6,584
  • 9
  • 35
  • 69

1 Answers1

1

The exception trace you posted above says you have a binding redirect in your application config file:

Redirect found in application configuration file: 6.0.0.0 redirected to 6.0.0.0.

Try changing it to redirect to the assembly version you're actually using:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

Important note: binding redirects use the Assembly Version, not the File Version. So for Json.Net 9.0.x, this would be 9.0.0.0. If you try to use the File Version as the newVersion of the redirect, the redirect will not work because it won't match the Assembly Version of the actual assembly.

Brian Rogers
  • 125,747
  • 31
  • 299
  • 300
  • Good suggestion, but making that change had no effect; same error. BTW, I checked project.lock.json, and only Microsoft.Azure.WebJobs/1.1.2 and WindowsAzure.Storage/7.2.1 call for 6.0.8. Is there some way to force them to accept the later version? – Mark Olbert Oct 12 '16 at 04:53
  • @MarkOlbert, does your WebJob project reference the other project which may references the old version of `Newtonsoft.Json`? Have you tried to clear the "Temporary ASP.NET Files" or reinstall the packages and clear your entire solution, then rebuild your project to see whether it could work as expected? – Bruce Chen Oct 12 '16 at 08:31
  • @Bruce, I've tried rebuilding the solution, cleaning and rebuilding, etc, several times. No joy. I used the nuget solution manager to ensure all references to NewtonSoft use the 9.0.1 version -- that's what causes the problem to show up (i.e., it compiles & runs fine if I force all projects to use 6.0.8, but I get warnings about version incompatibilities). I'll live with the warnings if I have to, but I'd like to get rid of them. Not sure where Temporary ASP NET Files are located -- FWIW, this is an MVC6/ASPNET5 site. – Mark Olbert Oct 12 '16 at 15:18
  • @Bruce: I spoke too soon. In the course of experimenting, I realized I hadn't exactly followed Brian Roger's suggestion. I'd modified the bindingRedirect line to be , since 9.0.8 is the latest version. Turns out that's incorrect (as I found out when I edited it to be 6.0.8.0 rather than 6.0.0.0). Setting it to 9.0.0.0 solves the problem. Why does bindingRedirect call for 4 digits if it ignores several of them? – Mark Olbert Oct 12 '16 at 15:29
  • @MarkOlbert it doesn't ignore the digits-- what's going on here is the binding redirect is using the Assembly Version, not the File Version. The assembly version for Json.Net 9.0.1 is 9.0.0.0. Same for 6.0.8 vs. 6.0.0.0. Sorry, I probably should have made that clear in my answer. – Brian Rogers Oct 12 '16 at 15:42
  • No worries, @Brian. I'd forgotten that nuance, and appreciate the education. – Mark Olbert Oct 13 '16 at 02:24