0

Our azure function was working fine with Newtonsoft.json nuget package version 13.0.1. We updated a code that is not related to the nuget and once deployed to Azure function ( the code referenced via nuget); we got the exception"Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified "

I am sure it is the runtime issue , we have not changed the newtonsoft reference version. Any idea?

Dan Hunex
  • 5,172
  • 2
  • 27
  • 38

1 Answers1

0

My .csproj code for below Azure Functions Test Case in checking the breaking changes for the NewtonSoft.Json NuGet Package:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
    <PackageReference Include="Newtonsoft.Json" Version="13.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>
  • Check if your Newtonsoft.Json NuGet Package version is compatible with the .NET version and Azure Functions Core Tools version.
  • The Same issue registered in SO 62853320 and resolved by the user @ThiagoCustodio like downgrading the Version of that NuGet Package and check the version compatibility with the other dependencies used in the Function Code.

Following these MS Doc1 & Doc2, Created a Sample code snippet to test any breaking changes in that NuGet Pakcage with the .NET 6 Azure Functions:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace KrishNet6FunAppAWJTest
{
    public class Account
    {
        public string Name { get; set; }
        public string Email { get; set; }
        public DateTime DOB { get; set; }
    }
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            Account account = new Account
            {
                Name = "John Doe",
                Email = "john@nuget.org",
                DOB = new DateTime(1980, 2, 20, 0, 0, 0, DateTimeKind.Utc),
            };

            string json = JsonConvert.SerializeObject(account, Formatting.Indented);
            Console.WriteLine(json);

            string responseMessage = "Hello Krishna, This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
        }
    }
}

enter image description here

Checked with the latest version of the NuGet Package Newtonsoft.Json with the Azure Functions .NET 6 Core with the sample code snippet and working successfully and check by downgrading the NuGet Package Version along with all other Code, Dependencies Versions Compatibility.