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

1
  • 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. Commented Jul 12, 2018 at 11:25

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much for taking the time on this! Now works perfectly!!
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?
@MasonWheeler If you still see2.0.11651.0, go check whether this folder%LocalAPPDATA%\AzureFunctionsTools\Releases\2.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.
0

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

Binding Redirect fix for V1 Azure function

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.