Azure Functions Newtonsoft.Json load error

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Azure Functions Newtonsoft.Json load error



This is driving me crazy. I am getting a load error with Azure functions with Newtonsoft.Json.



This is a .netstandard2.0 project and I have version 11.0.2 installed. I have looked on the web and most others that have had this are using an old version of the Microsoft.NET.Sdk.Functions : 1.0.13 But I am using 1.0.14



See my project file below :


<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<RootNamespace>modoapi</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta5" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="3.0.0-beta5" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.14" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>



I have looked at all the dependencies for my project and they all point to Newtonsoft.Json 11.0.2.



The file exists in my output bin folder. I have cleaned the solution. Updated to latest VS and Azure Functions and WebJobs Tools 15.0.40608.0



The Function App starts ok but when I add a message to the queue to invoke a trigger I get the following error in the console.



[12/07/2018 10:56:36] Executed 'ExecuteWorkItem' (Failed,
Id=6d87f5e9-c331-4934-a3f3-b9bebf756b54) [12/07/2018 10:56:36]
System.Private.CoreLib: Exception while executing function:
ExecuteWorkItem. test-api: Could not load file or assembly
'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific
file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib:
Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.



Here is the signature for my function


public static class ExecuteWorkItem
{
[FunctionName("ExecuteWorkItem")]
public static async Task Run(
[QueueTrigger("work-item")]string queueItem,
TraceWriter log,
ExecutionContext executionContext,
[Inject(typeof(IWorkItemEngine))]IWorkItemEngine workItemEngine,
[Table("ResultData", Connection = "AzureWebJobsStorage")] CloudTable resultTable,
[Table("SimulationNodeData", Connection = "AzureWebJobsStorage")] CloudTable simulationNodeTable)



Any ideas would be really appreciated right now, the only other person that seems to be having a similar problem is this guy here: Go to the bottom of his post



He had no reply to his query and he is on a Mac environment whereas I am on windows 10.



Any help would be really appreciated.



Thanks in advance





BTW I am using Autofac for dependency injection. Autofac does not seem to have any reference to Newtonsoft.Json. But to prove a point I have tried removing the Autofac package and my Inject Attributes and the error is still there.
– Lenny D
Jul 12 at 11:25




1 Answer
1



For v2 functions, Function sdk 1.0.14 references Newtonsoft.Jon v11.0.2 by default, no need to reference it explicitly, same with Microsoft.Azure.WebJobs. The problem is about the function core tools(CLI) your VS uses.



Check this line of CLI output when debugging locally.


Starting Host (HostId=xx, InstanceId=xxx, Version=2.0.11651.0, ...)



If you see Version=2.0.11651.0 exactly, it means your VS is consuming old version of CLI.


Version=2.0.11651.0



Actually latest version of Azure Functions and Web Jobs Tools(on VS menus, Tools> Extensions and Updates) is 15.0.40617.0. This version consumes the latest CLI(host version 2.0.11888 right now), where v11 Json.Net has been well supported. Update this extension may solve your problem.



It seems Visual Studio for Mac still leverages old CLI(host version 2.0.11651), Mac users can download new function core tools using Homebrew and run func start in Content root path. Or switch update channel to update their VS to latest/preview version.


func start





Thank you so much for taking the time on this! Now works perfectly!!
– Lenny D
Jul 12 at 13:12





I'm seeing this problem (and the 2.0.11651.0 version) with the latest Azure Functions and Web Jobs Tools extension (15.0.40617.0, as you mentioned). Any idea why it's stuck at the old version?
– Mason Wheeler
Aug 8 at 4:10





@MasonWheeler If you still see2.0.11651.0, go check whether this folder%LocalAPPDATA%AzureFunctionsToolsReleases2.3.3exists, which contains cli, templates and manifest.json. If the downloading turns out failed, just delete %LocalAPPDATA%AzureFunctionsTools folder and restart VS to download again. If still no luck, See update part of this post to download it manually, note now the host version is 2.0.11946.0 and the folder is 2.3.3.
– Jerry Liu
Aug 8 at 5:02



2.0.11651.0


%LocalAPPDATA%AzureFunctionsToolsReleases2.3.3


%LocalAPPDATA%AzureFunctionsTools


2.0.11946.0


2.3.3





Thanks, manually downloading it worked.
– Mason Wheeler
Aug 8 at 11:56






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered