Azure Functions Newtonsoft.Json load error

5

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

c#
azure
json.net
azure-functions
asked on Stack Overflow Jul 12, 2018 by Lenny D

2 Answers

5

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.

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.

answered on Stack Overflow Jul 12, 2018 by Jerry Liu • edited Aug 25, 2018 by Jerry Liu
0

For V1 functions, the following link helps to resolve Binding redirect issue

Binding Redirect fix for V1 Azure function

answered on Stack Overflow Jun 10, 2019 by Joe 89

User contributions licensed under CC BY-SA 3.0