Newtonsoft.Json fails to load in local Azure Functions app

2

I'm developing an Azure Functions "app" and I'm doing most of the testing locally then publishing the DLLs to Azure. I started out in March and it's been working pretty well up until a couple of weeks ago.

I'm mainly developing and testing using macOS High Sierra (currently the latest one; 10.13.4) and Visual Studio on the stable channel.

I updated Visual Studio recently when it prompted me to and it seems to have been updated to favor .NETStandard 2.0 over .NET Framework 4.7.*, but my project stayed on .NET Framework 4.7. Nevertheless, when I tried to run my timer triggers through a POST request to the admin-endpoint, I'm presented with an error telling me the application can't load Newtonsoft.Json.

I was struggling with that for a while and ended up creating a new project with .NETStandard 2.0 and just copied the files over, but the same error persisted.

Newtonsoft.Json is installed from the built-in NuGet package manager in Visual Studio for Mac.

I've also tested the same project on Windows (Windows Server 2012 R2 Standard), but I'm getting the exact same error.

Error I'm getting:

[06/05/2018 08:17:18] System.Private.CoreLib: Exception while executing function: Posts. MyAzureFunctionsApp: 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'.
[06/05/2018 08:17:18] 
[06/05/2018 08:17:18] Executed 'Posts' (Failed, Id=7c288cdf-7807-4450-92cd-c64370e241a5)
[06/05/2018 08:17:18] System.Private.CoreLib: Exception while executing function: Posts. MyAzureFunctionsApp: 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'.

Newtonsoft.Json version 11.0.0 doesn't exist, it's currently at version 11.0.2 and the DLL states version 11.0.2.21924, so I tried a "binding redirect." That doesn't seem to make any difference either.

app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json"
                publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
      <bindingRedirect oldVersion="11.0.0.0" newVersion="11.0.2.21924"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

CSProj-file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
  </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've cleaned the project a dozen times, created a brand new project, deleted ~/.nuget, reinstalled Visual Studio and tested the same project on Windows. But I'm still getting the same error each time.

c#
json.net
azure-functions
asked on Stack Overflow Jun 5, 2018 by Vetle Økland • edited Jun 5, 2018 by Vetle Økland

1 Answer

6

Binding redirects are not supported yet (GitHub issue).

Microsoft.NET.Sdk.Functions 1.0.13 has Newtonsoft.Json 10.0.3 as a dependency, when targeting netstandard2.0 (NuGet package).

answered on Stack Overflow Jun 5, 2018 by trydis

User contributions licensed under CC BY-SA 3.0